Oliver Watkins
Oliver Watkins

Reputation: 13499

Disable Multi-Row selecton in ExtJS Grid

There is already a similar question in SO to my quesiton :

Ext js Editor Grid Disable Multiple Row Selection

But the accepted answer is wrong. It says to use RowSelectionModel as a property like so :

selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),

But in the API no such thing exists (maybe they are talking about a different extjs version).

How can you disable multi selection in Extjs grids? ie. No SHIFT or CTRL multi select. Only single selections are allowed.

Upvotes: 1

Views: 2497

Answers (1)

Scriptable
Scriptable

Reputation: 19750

Refer to the documentation

It shows that you can specify the selection model like so:

Grids use a Row Selection Model by default, but this is easy to customise like so:

Ext.create('Ext.grid.Panel', {
    selType: 'cellmodel',
    store: ...
});

Or the alternative option would be:

Ext.create('Ext.grid.Panel', {
    selType: 'rowmodel',
    store: ...
});

EDIT:

You need to specify the Selection Model MODE

Fiddle

Ext.application({
    name: 'MyApp',

    launch: function() {
        var store = Ext.create('Ext.data.Store', {
            storeId: 'simpsonsStore',
            fields: ['name', 'email', 'phone'],

            proxy: {
                type: 'ajax',
                url: 'data1.json',
                reader: {
                    type: 'json',
                    rootProperty: 'items'
                }
            },
            autoLoad: true
        });


        Ext.create("Ext.grid.Panel", {
            title: 'Simpsons',
            renderTo: Ext.getBody(),
            store: Ext.data.StoreManager.lookup('simpsonsStore'),
            selModel: new Ext.selection.RowModel({
                mode: "SINGLE"
            }),
            columns: [{
                text: 'Name',
                dataIndex: 'name'
            }, {
                text: 'Email',
                dataIndex: 'email',
                flex: 1
            }, {
                text: 'Phone',
                dataIndex: 'phone'
            }],
            height: 200,
            width: 400,
        });

    }

});

Upvotes: 3

Related Questions