在 Kendo UI 网格中控制组顺序 [英] Controlling Group order in a Kendo UI Grid

查看:20
本文介绍了在 Kendo UI 网格中控制组顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法控制 Kendo UI 网格中的分组顺序.有一个组我想排在所有其他组之前,但似乎 Kendo UI 网格按字母顺序对组进行排序.我知道在分组名称中添加一个空格是可行的,但这似乎很不友好.

谢谢狮子座

解决方案

目前没有办法根据组字段以外的其他内容对分组进行排序.有一种像 Telerik 在他们的非剑道网格中那样对组进行排序的方法是我现在对他们最大的功能要求.所以我们现在只能使用 hacks.

对我有用的一个技巧是将排序字段和显示字段组合成一个新的字符串列,将排序字段部分隐藏在隐藏的跨度内.这是在数据源端完成的(对我来说,在 SQL 中).即使排序字段是数字,新列也会作为字符串排序,因此在某些情况下您必须适当填充.

例如,如果我的数据是:

<预><代码>[{'姓名': '爱丽丝',排名":10,'RankName': '<span class="myHiddenClass">10</span>Alice',...(其他领域)},{'姓名':'鲍勃','排名':9,'RankName': '<span class="myHiddenClass">09</span>Bob',...(其他领域)},{'名称': '夏娃',排名":11,'RankName': '<span class="myHiddenClass">11</span>Eve',...(其他领域)}...(多个 Alice/Bob/Eve 记录)]

然后我可以按 RankName 字段而不是 Name 字段进行分组.它将在组标题中显示名称字段,但按等级字段排序.在这种情况下,即使 Alice 按字母顺序排在第一位,Bob 也会作为第一组出现.这与您提到的空间填充类似.

Is there a way to control the order of the grouping in a Kendo UI grid. There is a group I would like to go before all other groups, but it seems Kendo UI grid sorts the groups alphabetically. I know that adding a space to the grouping name works but that's seems very hackish.

Thanks Leo

解决方案

There is currently no way to sort a grouping on something other than the group's field. Having a way to sort groups like Telerik does in their non-Kendo grids is my biggest feature request for them right now. So we are stuck using hacks for now.

One hack that works for me is to combine the sorting field and the display field into a new string column that hides the sorting field portion inside a hidden span. This is done on the data source side (for me, in SQL). The new column is then sorted as a string even if the sorting field was a number, so you have to pad appropriately in some cases.

For example, if my data was:

[ 
    { 
      'Name': 'Alice', 
      'Rank': 10, 
      'RankName': '<span class="myHiddenClass">10</span>Alice', 
      ... (other fields)
    },  
    { 
      'Name': 'Bob', 
      'Rank': 9, 
      'RankName': '<span class="myHiddenClass">09</span>Bob', 
      ... (other fields)
    },  
    { 
      'Name': 'Eve', 
      'Rank': 11, 
      'RankName': '<span class="myHiddenClass">11</span>Eve', 
      ... (other fields)
    } 
    ... (Multiple Alice / Bob / Eve records)
]

Then I can group by the RankName field instead of the Name field. It will display the Name field in the group header but be sorted by the Rank field. In this case, Bob will show up as the first group even though Alice was first alphabetically. This works similarly to the space padding you mentioned.

这篇关于在 Kendo UI 网格中控制组顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆