[1.0a2 Rev 5] Grid sorting - Ext JS

本文探讨了使用ExtJS框架创建网格时遇到的排序问题,具体表现为后台接收的排序参数与预期不符的情况。作者详细展示了配置记录、读取器、数据存储及列模型的过程,并针对点击列头进行排序时出现的问题进行了讨论。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I have:

Record config
Item = Ext.data.Record.create([
  {name: 'id', mapping: 'id', type: 'int'},
  {name: 'publishDate', mapping: 'publish_date', type: 'date', dateFormat: 'Y-m-d H:i:s'},
]);
Reader
reader = new Ext.data.JsonReader({
  root: 'list',
  totalProperty: 'totalCount',
  id: 'id'
}, Item);
Data Store
ds = new Ext.data.Store({
  proxy: new Ext.data.HttpProxy({url: 'news/getlist'}),
  reader: reader,
  remoteSort: true
});
ds.setDefaultSort('publish_date', 'desc');
Column Model
cm = new Ext.grid.ColumnModel([{
  id: 'id',
  header: 'Id',
  dataIndex: 'id',
  width: 20
},{
  id: 'publishDate', // id assigned so we can apply custom css (e.g. .x-grid-col-login b { color:#333 })
  header: 'Publish Date',
  dataIndex: 'publishDate',
  renderer: renderPublishDate,
  width: 100
}]);
cm.defaultSortable = true;
and Grid
grid = new Ext.grid.Grid('news-grid', {
  ds: ds,
  cm: cm,
  selModel: new Ext.grid.RowSelectionModel({singleSelect: true}),
  enableColLock: false
});
standard config.

When I click on "Publish Date" column, my backend recieves param "sort=publishDate", but I expect, that it must be "sort=publish_date".

Bug, or I'm doing something wrong?
Reply With Quote
  #2  
Old 02-28-2007, 04:37 AM
Default

Is that wrong? I just have the "name" property in my Ext.data.Record (I don't know what "mapping" does!)

And in my ColumnModel, the "dataIndex" property refers to that name to get the value from the Record.

I set the name to be the actual HQL (SQL) expression that generated that column, so all is well for me... I don't want this to change!
Reply With Quote
  #3  
Old 02-28-2007, 11:38 AM
Default

Arikon, please don't make a new thread for everything you think is a bug.

This has been discussed before and it is not a bug. For your mapping (a simple string name) it may make sense, but everyone's may not be as simple. For example, sending: 'Item/Name[@type]' back to the server would be worthless.
Reply With Quote
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值