在ExtJS 3 EditorGridPanel中按渲染值排序
我是Ext新手,如果我的问题不够清楚/太基本,我会提前道歉 我有一个Ext.grid.EditorGridPanel,其中有一个Ext.data.Store和一个Ext.data.JsonReader 我有以下问题: 我想对网格中的列进行排序,但从存储中返回的值不是我希望排序的值(返回的值是一个ID,我希望按照该ID映射到的字符串进行排序) 我有一个在这个ID和字符串值之间转换的渲染函数,但我不知道如何将它集成到我的代码中 我发现这个帖子: 这看起来与我的需求相似,但当我尝试添加:在ExtJS 3 EditorGridPanel中按渲染值排序,extjs,extjs3,Extjs,Extjs3,我是Ext新手,如果我的问题不够清楚/太基本,我会提前道歉 我有一个Ext.grid.EditorGridPanel,其中有一个Ext.data.Store和一个Ext.data.JsonReader 我有以下问题: 我想对网格中的列进行排序,但从存储中返回的值不是我希望排序的值(返回的值是一个ID,我希望按照该ID映射到的字符串进行排序) 我有一个在这个ID和字符串值之间转换的渲染函数,但我不知道如何将它集成到我的代码中 我发现这个帖子: 这看起来与我的需求相似,但当我尝试添加: {name
{name: 'my_field', sortType: my_render_function}
对我的JsonReader来说,它不起作用
我哪里弄错了
谢谢
应帕特的要求:
var my_render = function(val, metaData, record, rowIndex, colIndex, store){
if (val == null)
return '';
var n = another_store.getById(val);
if (n == null)
return '';
return n.data.name;
};
var my_reader = new Ext.data.JsonReader({
root: 'my_root',
id: 'tissue_num',
}, [{
name: 'tissue_num',
type: 'int'
}, 'tissue_desc', 'organ']
);
var my_store = new Ext.data.Store({
url: request_url,
baseParams: {
_state: request_state,
_action: 'get_conditions'
},
sortInfo: {
field: 'tissue_num',
direction: "ASC"
},
reader: my_reader,
pruneModifiedRecords: true
});
因为您需要的不仅仅是显示转换,所以我不会在这里使用渲染器,而是记录定义中的数据
val convertName = function(val, rec) {
// val will always be null since there's no field named 'name'
var id = rec.data.tissue_num;
if (id == null)
return '';
var n = another_store.getById(id);
if (n == null)
return '';
return n.data.name;
};
var my_reader = new Ext.data.JsonReader({
root: 'my_root',
id: 'tissue_num',
}, [{
name: 'tissue_num',
type: 'int'
}, {name: 'name', convert: convertName},
'tissue_desc', 'organ']
);
这将为您提供一个记录,其中包含
name
字段中的数据,您可以对从服务器获得的实际数据执行任何操作-排序、筛选、显示等。这比每次需要时都尝试提取渲染值要容易。您能提供一些代码吗?排序功能和JSON阅读器?优秀的解决方案!!!这工作做得很好!使用convert确实是我所缺乏的。谢谢你,韦斯。