开发者

ExtJS GridPanel numberColumn - sort issue

开发者 https://www.devze.com 2023-01-13 01:28 出处:网络
I have a grid Panel with 4 columns, one of these is numeric (number up to 4 digit), and I would like to sort the row by this colum. My problem is Ext JS sorts the rows as if the column was textual, so

I have a grid Panel with 4 columns, one of these is numeric (number up to 4 digit), and I would like to sort the row by this colum. My problem is Ext JS sorts the rows as if the column was textual, so 5 is sorted after 3000.

I tried to use a numberColumn instead of a normal column (specifying the x-type in the columns of the GridPanel), but it doesn't change the sorting.

Thus I tried to format the numbers so 5 would appear like 0005, and 0005 would be before 3000. But the format options of the numberColumn do not appear to let me specify a minimal number of digit (in Java, using NumberFormat, 000开发者_开发问答0 would work, but here it doesn't).

So I put a renderer to force my number to appear with 4 digits, it works, but it seems that the sort method use the values before beeing rendered, wich is quite logical.

I'm stuck after trying all my ideas, does anyone have a clue?


If you're using a remote store sort, then the sorting is done remotely (the database, like mysql). So what is the type of column on the database for that field? If it's a char or varchar, then that's the issue.


I've had a similar issue, the column type doesn't fix this. To have a proper ordering the type in model should be numeric.

1) Set your field type as integer in model definition.

Ext.define('myModel', {
  extend: 'Ext.data.Model',
  fields: [{ name: 'myField', type: 'int' }]
});

2) Create a Store using that model.

var myStore = Ext.create('Ext.data.Store',{
  model: 'myModel'
});

3) Define a GridPanel using the store and link your field as dataIndex into columns definition.

Ext.create('Ext.grid.Panel',{
  store: myStore,
  columns: [{
    header: 'Numbers',  dataIndex: 'myField'
  }]
});


I encountered a similar problem where by exj grids sort by each digit in your number, so for example a list might be reordered to 1, 2, 22, 3, 4, 41, 5... for what its worth, i found in extjs4, that defining the type as int in the model did the trick, I havent specified the local or remote sort but it seems to be working...


Ext.define('ExtMVC.model.Contato', {
  extend: 'Ext.data.Model',
  fields: [{'id', type: 'int'}, 'name', 'phone', 'email']
});

This is my code that connects to a MySQL. I followed this -> {'id', type: 'int'}, and it work out fine... Thank you all! I'm using Ext js 4.2.x

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号