2010-12-03 30 views
4

我處理的屬性網格。我想防止自動排序屬性網格的列名稱。 這是我的代碼。大膽突出顯示的代碼是屬性網格的源代碼,它的順序就像我想看到的一樣。但Ext按字母順序自動排列列順序。我怎樣才能防止這一點。禁用自動分揀物業電網ExtJS的

感謝您的任何建議。

 
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); 

回答

8

是的。我已經完成了。這是解決方案。

 
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 
+0

用戶可能仍然想對列進行排序,但只想禁用在渲染時完成的自動排序。 – goodies4uall 2013-09-17 15:33:40

6

這不會對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 

你可以試試這個:

p.getStore().sorters.items = [] // which should remove sorting information from the store 
p.setSource(source) // now load the data 
2

對於ExtJS的3.4應該只需要:

delete propertygrid.getStore().sortInfo; 
0

這是我這樣做的方式: 當我定義我的專欄我設置sortable property to false和我定義自己的「排序標誌」,像這樣:

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

當列標題,用戶點擊(在headerclick事件被觸發)後,我檢查,如果該列排序或者不是,如下所示:

onHeaderClick: function(ct, column, e) { 
    if (column.sortableColumn) { 
     // do your own sorting ... 
    } 
}