Extjs网格,包含来自json对象的数据,并进行排序

Extjs网格,包含来自json对象的数据,并进行排序,extjs,extjs4.1,Extjs,Extjs4.1,我正在尝试显示网格。在这种情况下,排序不起作用。这是我的密码 <div id="grid-sample"></div> <script type="text/javascript"> Ext.create('Ext.data.Store', { storeId:'cstore', fields:['user', 'age', 'place'], data:

我正在尝试显示网格。在这种情况下,排序不起作用。这是我的密码

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

Ext.create('Ext.data.Store'{
storeId:'cstore',
字段:[“用户”、“年龄”、“地点”],
数据:[
{“用户”:“乔”,“年龄”:27,“地点”:“悉尼”},
{“用户”:“亚伯”,“年龄”:29,“地点”:“德里”},
{“用户”:“财务”、“年龄”:18,“地点”:“圣何塞”}
]
});
Ext.create('Ext.grid.Panel'{
标题:“示例网格”,
存储:Ext.data.StoreManager.lookup('cstore'),
自动创建视口:false,
布局:“适合”,
栏目:[
{text:'Name',xtype:'templatecolumn',tpl:'{user}',sortable:true},
{text:'Age',xtype:'templatecolumn',tpl:'{Age}',sortable:true},
{text:'Place',xtype:'templatecolumn',tpl:'{Place}',sortable:true}
],
宽度:750,
renderTo:“网格示例”
});

您需要添加数据索引,以便排序工作

所以你的专栏看起来像

 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的值应与存储中的字段名匹配。

如果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"}
]

我想没有人回答这个问题:(