2013-07-15 46 views
0

我想顯示一個網格。在這種排序不工作。這是我的代碼。Extjs網格與數據從json對象與排序

<div id="grid-sample"></div> 
    <script type="text/javascript"> 
     Ext.create('Ext.data.Store', { 
      storeId:'cstore', 
      fields:['user', 'age', 'place'], 
      data: [ 
         {"user":"joe","age":27,"place":"sydney"}, 
         {"user":"abel","age":29,"place":"delhi"}, 
         {"user":"fin","age":18,"place":"san jose"} 
        ] 

     }); 

     Ext.create('Ext.grid.Panel', { 
      title: 'Sample grid', 
      store: Ext.data.StoreManager.lookup('cstore'), 
      autoCreateViewPort: false, 
      layout: 'fit', 
      columns: [ 
       { text: 'Name', xtype: 'templatecolumn', tpl: '{user}' ,sortable : true }, 
       { text: 'Age', xtype: 'templatecolumn', tpl: '{age}' ,sortable : true }, 
       { text: 'Place', xtype: 'templatecolumn', tpl: '{place}',sortable : true } 
      ], 
      width: 750, 
      renderTo: 'grid-sample' 
     }); 
    </script> 

回答

0

您需要添加dataIndex排序工作。

所以你列的樣子,

columns: [ 
    { text: 'Name', xtype: 'templatecolumn',tpl: '{user}',dataIndex: 'user' ,sortable : true }, 
    { text: 'Age', xtype: 'templatecolumn', tpl: '{age}',dataIndex: 'age' ,sortable : true }, 
    { text: 'Place',xtype: 'templatecolumn', tpl: '{place}', dataIndex :'place',sortable : true }] 

dataIndex值應該在店裏的字段名稱相匹配。

+0

謝謝。這工作正常。 – ejo

0

如果dataIndex不應該是指一個領域,而是一個對象的屬性是什麼?所以從上面的數據可能是

data: [{{"user":"joe",userName:"Joeschmoe"},"age":27,"place":"sydney"}, 
{{"user":"Jane",userName:"Jany"},"age":29,"place":"delhi"}, 
{{"user":"Mary",userName:"mary123"},"age":18,"place":"san jose"} 
]