Sorting 为什么我的ExtJS 4.2 gridpanel排序不起作用?
不确定为什么我的排序不适用于此gridpanel 我正确地设置了分类器属性 我还设置了sortOnLoad属性 不知道为什么这个简单的案例不起作用Sorting 为什么我的ExtJS 4.2 gridpanel排序不起作用?,sorting,extjs4,gridpanel,Sorting,Extjs4,Gridpanel,不确定为什么我的排序不适用于此gridpanel 我正确地设置了分类器属性 我还设置了sortOnLoad属性 不知道为什么这个简单的案例不起作用 Ext.onReady(function() { Ext.define('com.myCompany.MyGridModel', { extend : 'Ext.data.Model', fields : [{ name : 'name', type : 'str
Ext.onReady(function() {
Ext.define('com.myCompany.MyGridModel', {
extend : 'Ext.data.Model',
fields : [{
name : 'name',
type : 'string'
}, {
name : 'address',
type : 'string'
}, {
name : 'type',
type : 'string'
}]
});
var store = Ext.create('Ext.data.Store', {
model: 'com.myCompany.MyGridModel',
proxy: {
type: 'ajax',
url: 'centers.json',
reader: {
type: 'json',
root: 'centers'
},
sortOnLoad: true,
sorters: { property: 'name', direction : 'ASC' }
}
});
store.load();
var grid = Ext.create('Ext.grid.Panel', {
layout: 'fit',
store: store,
columns: [{
text: 'Name',
dataIndex: 'name',
name: 'name'
}, {
text: 'IP Address',
dataIndex: 'address',
name: 'address'
}, {
text: 'Type',
dataIndex: 'type',
name: 'type'
}],
renderTo: Ext.getBody(),
});
grid.getView().refresh();
});
{
"centers": [
{
"name": "South Test Center",
"address": "30.40.50.60",
"type": "TestType2"
},
{
"name": "East Test Center",
"address": "50.60.70.80",
"type": "TestType1"
},
{
"name": "West Test Center",
"address": "40.50.60.70",
"type": "TestType3"
},
{
"name": "North Test Center",
"address": "20.30.40.50",
"type": "TestType4"
}
]
}
我不认为我需要在这种情况下进行远程排序,所以只是不确定为什么这不起作用
Ext.onReady(function() {
Ext.define('com.myCompany.MyGridModel', {
extend : 'Ext.data.Model',
fields : [{
name : 'name',
type : 'string'
}, {
name : 'address',
type : 'string'
}, {
name : 'type',
type : 'string'
}]
});
var store = Ext.create('Ext.data.Store', {
model: 'com.myCompany.MyGridModel',
proxy: {
type: 'ajax',
url: 'centers.json',
reader: {
type: 'json',
root: 'centers'
},
sortOnLoad: true,
sorters: { property: 'name', direction : 'ASC' }
}
});
store.load();
var grid = Ext.create('Ext.grid.Panel', {
layout: 'fit',
store: store,
columns: [{
text: 'Name',
dataIndex: 'name',
name: 'name'
}, {
text: 'IP Address',
dataIndex: 'address',
name: 'address'
}, {
text: 'Type',
dataIndex: 'type',
name: 'type'
}],
renderTo: Ext.getBody(),
});
grid.getView().refresh();
});
{
"centers": [
{
"name": "South Test Center",
"address": "30.40.50.60",
"type": "TestType2"
},
{
"name": "East Test Center",
"address": "50.60.70.80",
"type": "TestType1"
},
{
"name": "West Test Center",
"address": "40.50.60.70",
"type": "TestType3"
},
{
"name": "North Test Center",
"address": "20.30.40.50",
"type": "TestType4"
}
]
}
sortOnLoad和sorters配置选项应直接放在商店上,而不是放在型号上 请参见此处的Ext.data.Store文档: 已回答: