Disable auto sorting on property grid in ExtJS
Asked Answered
H

4

5

I am dealing with property grid. I want to prevent auto sorting of column names for property grid. here is my code. Bold highlighted code is my source for property grid and its order is just like I want to see. But Ext is auto sorting column orders alphabeticly. How can I prevent that.

Thanks for any suggestion.

Ext.ns('Application.propertygrid');
Application.propertygrid.FileDetail = Ext.extend(Ext.grid.PropertyGrid, {
    title: 'File Detail',
    height: 200,
    border: false,
    stripeRows: true,
    flex: 1,
    initComponent: function () {
        Application.propertygrid.FileDetail.superclass.initComponent.apply(this, arguments);
    },
    source: {
        Name: 'Please select a file',
        Type: 'Please select a file',
        Size: 'Please select a file',
        Path: 'Please select a file',
        FullPath: 'Please select a file',
        Width: 'Please select a file',
        Height: 'Please select a file'
    },
    listeners: {
        beforeedit: function(){
            return false; // prevent editing 
        },
        headerclick: function(){
            return false; // prevent column sorting on click
        }
    }
})
Ext.reg('filedetail', Application.propertygrid.FileDetail);
Herald answered 3/12, 2010 at 20:57 Comment(0)
H
8

Yeah. I've done with it. And here is the solution.

var p = new Ext.grid.PropertyGrid({
  ...
  // do not specify 'source' here
});

delete p.getStore().sortInfo; // Remove default sorting
p.getColumnModel().getColumnById('name').sortable = false; // set sorting of first column to false
p.setSource(source); // Now load data
Herald answered 4/12, 2010 at 15:29 Comment(1)
User may still want to sort the columns but just wants to disable the auto sorting done on rendering.Airdrie
L
7

This will not work for the Extjs 4:

delete p.getStore().sortInfo; // Remove default sorting
p.getColumnModel().getColumnById('name').sortable = false; // set sorting of first column to false
p.setSource(source); // Now load data

You can try this:

p.getStore().sorters.items = [] // which should remove sorting information from the store
p.setSource(source) // now load the data
Lychnis answered 12/3, 2013 at 12:56 Comment(0)
A
2

For Extjs 3.4 should only need:

delete propertygrid.getStore().sortInfo;
Airdrie answered 17/9, 2013 at 15:32 Comment(0)
M
0

This is the way I do this: When I define my columns I set the sortable property to false and I define my own 'sortable flag', like this:

var column = {
            xtype: 'column-component',
            ...
            sortable: false,
            sortableColumn: true
        }

Later when a user clicks on the column header (the headerclick event gets triggered) and I check if the column is sortable or not, like this:

onHeaderClick: function(ct, column, e) {
    if (column.sortableColumn) {
        // do your own sorting ... 
    }
}
Marta answered 4/9, 2014 at 13:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.