0

我正在尝试显示一个网格。在这种排序中不起作用。这是我的代码。

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

2 回答 2

1

如果 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"}
]
于 2015-07-28T14:57:48.873 回答
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的值应与存储中的字段名称匹配。

于 2013-07-15T10:48:02.000 回答