最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Extjs sorting store by alphanumeric field - Stack Overflow

programmeradmin1浏览0评论

I've got a bunch of records whose names are like "Itemtype #", and when they are outputted into a tree view, they're sorted incorrectly, like so:

  • Item 1
  • Item 10
  • Item 11
  • Item 12
  • Item 13
  • Item 2
  • Item 3
  • Item 4

My model fields are defined as follows, and I am sorting on "Name":

fields: [
  { name: 'Id', defaultValue: 0, type: 'int', mapping: 'Id' },
  { name: 'Name', defaultValue: '', type: 'string', mapping: 'Name', sortType: Ext.data.SortTypes.asUCString },
  { name: 'Type', defaultValue: 0, type: 'int', mapping: 'Type' },
  { name: 'CreationDate', type: 'date', mapping: 'CreationDate' }
],

Can anybody point me in the right direction? I'm using extjs 4.0.5

I've got a bunch of records whose names are like "Itemtype #", and when they are outputted into a tree view, they're sorted incorrectly, like so:

  • Item 1
  • Item 10
  • Item 11
  • Item 12
  • Item 13
  • Item 2
  • Item 3
  • Item 4

My model fields are defined as follows, and I am sorting on "Name":

fields: [
  { name: 'Id', defaultValue: 0, type: 'int', mapping: 'Id' },
  { name: 'Name', defaultValue: '', type: 'string', mapping: 'Name', sortType: Ext.data.SortTypes.asUCString },
  { name: 'Type', defaultValue: 0, type: 'int', mapping: 'Type' },
  { name: 'CreationDate', type: 'date', mapping: 'CreationDate' }
],

Can anybody point me in the right direction? I'm using extjs 4.0.5

Share Improve this question edited Apr 18, 2013 at 23:00 wes 8,1856 gold badges32 silver badges41 bronze badges asked Apr 18, 2013 at 21:58 Grahame AGrahame A 3,95312 gold badges47 silver badges70 bronze badges 1
  • Well the sorting callback isn't working properly likely due to an override somewhere else in our app, but it is the correct way to do this. We're sorting the sql now instead. – Grahame A Commented Apr 19, 2013 at 14:41
Add a comment  | 

2 Answers 2

Reset to default 16

In store you have to set up how the data will display by sorters property:

var store = Ext.create('Ext.data.JsonStore', {
  .
  .
  .
  remoteSort: false, //true for server sorting
  sorters: [{
     property: 'Name',
     direction: 'DESC' // or 'ASC'
   }],
  .
  .
  .

})

Try calling TreeStore.sort with a sorter config with a sorting callback. A simple field sort won't do in this case because the naive alpha sort isn't what you want. The example at the top of the Ext.util.Sorter doc shows how to do it in a store, but you can just as easily add it to the sorters param of your model.

发布评论

评论列表(0)

  1. 暂无评论