Vec001
Vec001

Reputation: 23

How to deselect only some rows in a grid?

I have a grid with all its rows selected, there is a column named CODE and what I need its only deselect those rows after clicking a button which CODE is 1 and let selected the other ones.

I have tried with deselectAll(); but this deselect all the rows in the grid.

Upvotes: 0

Views: 1732

Answers (1)

Jaydeep
Jaydeep

Reputation: 1716

You can use deselect method on selectionModel to remove the selection of an item. You can pass either array of records to be deselected or an index of record. Below is the sample code.

Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: ['name', 'email', 'phone']
});

var userStore = Ext.create('Ext.data.Store', {
    model: 'User',
    data: [{
            name: 'Lisa'
        }, {
            name: 'Bart'
        }, {
            name: 'Homer'
        }
    ]
});

Ext.create('Ext.grid.Panel', {
    renderTo: Ext.getBody(),
    store: userStore,
    storeId: 'mystore',
    width: 300,
    height: 400,
    title: 'Application Users',
    listeners: {
        afterrender: function() {
            this.getSelectionModel().select(1, true); 
        }
    },
    tbar: [
        {
            xtype: 'button',
            text: "Deselect",
            handler: function() {
                this.up('grid').getSelectionModel().deselect(1); //deseleting record on 1st index
            }
        }    
    ],
    columns: [{
        text: 'Name',
        width: 300,
        sortable: false,
        hideable: false,
        dataIndex: 'name'
    }]
});

Upvotes: 1

Related Questions