简体   繁体   English

ExtJS分组网格排序错误

[英]ExtJS Grouping Grid sorting bug

I have a grouping grid that groups by a field, lets say the group is 'team'. 我有一个按字段分组的分组网格,可以说该组是“团队”。 Then all the players in that team have a number and other fields such as name, contract start and end date. 然后,该团队中的所有球员都有一个号码以及其他字段,例如姓名,合同开始和结束日期。

Within the teams I can sort in alphabetical order by name of a player, and by dates as well. 在团队中,我可以按球员的姓名和日期按字母顺序排序。 The sorting works on those fields. 排序在这些字段上进行。

The issue is when I try to sort by player number it sorts the following way. 问题是,当我尝试按玩家编号排序时,它会通过以下方式进行排序。

Assume we have players 1 through 30. 假设我们有玩家1到30。

The ascending order in my grid will be: 我的网格中的升序为:

1 10 11 12 13 14 15 16 17 18 19 2 20 21 etc.

Apparently for some reason it only compares the first digits but then between the teens it knows which ones come first (?). 显然由于某种原因,它只比较前几个数字,然后才比较两个十几岁之间的数字(?)。

I want the numbers sorted in a logical ascended order: 我希望数字按逻辑升序排序:

1 2 3 4 5 6 7 8 9 10 11 12 ... 20 21 22 ... 29 30

I am using ExtJS 3.3.1 grouping view in grid. 我在网格中使用ExtJS 3.3.1分组视图。 The data for the grid store is coming from java objects and all the fields are strings. 网格存储的数据来自java对象,所有字段均为字符串。

Thanks! 谢谢!

Strings always sort this way in js. 字符串在js中总是以这种方式排序。 Try "2" > "10" in the console. 在控制台中尝试"2" > "10" You have to use a number type field on the model or the store. 您必须在模型或商店上使用数字类型字段。 Like this: 像这样:

fields: [
    {name: '...', type: 'int'}
]

When doing Array sort functions, use parseInt(...) to convert to numbers first. 执行数组排序功能时,请先使用parseInt(...)将其转换为数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM