【问题标题】:Sorting by the rendered value in an ExtJS 3 EditorGridPanel在 ExtJS 3 EditorGridPanel 中按渲染值排序
【发布时间】:2012-04-04 01:36:38
【问题描述】:

我是 Ext 的新手,所以如果我的问题不够清楚/太基本,我提前道歉......

我有一个带有 Ext.data.Store 和 Ext.data.JsonReader 的 Ext.grid.EditorGridPanel。

我有以下问题:

我想让我的网格中的列可排序,但从我的商店返回的值不是我想要排序的值(返回的值是一个 ID,我想按这个字符串排序ID 映射到)。

我有一个渲染函数可以在这个 ID 和字符串值之间进行转换,但我不知道如何将它集成到我的代码中。

我找到了这篇文章:

http://www.sencha.com/forum/showthread.php?45324-Grid-column-sorting-on-rendered-value

这看起来与我的需要相似,但是当我尝试添加时:

{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
});

【问题讨论】:

  • 你能提供一些代码吗?排序函数和 JSON 阅读器?

标签: extjs extjs3


【解决方案1】:

由于您想要的不仅仅是显示转换,我不会在这里使用渲染器,而是convert 记录定义中的数据。

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 字段中的数据记录,您可以对从服务器获得的实际数据执行任何操作 - 排序、过滤、显示等。比试图找出每次需要时呈现价值。

【讨论】:

  • 优秀的解决方案!!!这非常有效! convert 的使用确实是我所缺乏的。谢谢你,韦斯。
猜你喜欢
  • 2011-07-31
  • 1970-01-01
  • 2017-07-31
  • 1970-01-01
  • 2014-01-08
  • 2011-03-06
  • 2012-06-29
  • 2011-03-28
  • 1970-01-01
相关资源
最近更新 更多