按多列对 Slickgrid 进行排序?
我刚刚开始为我正在从事的项目测试 Slickgrid,并且给我留下了深刻的印象它的性能。我的一项要求是对多列进行排序。我没有完全专注于 Slickgrid 中的 Dataview,所以也许我错过了一些明显的东西,但是有没有办法对多列上的网格进行排序?即使用户界面无法处理多个排序,我也希望能够按顺序调用列的函数,再加上升序或降序。我可以使用 Datatables 执行此操作,但它没有分组(项目的另一个要求)。
在最坏的情况下,我将求助于在服务器上进行排序并将内容以静态方式返回给客户端。
I just started testing out Slickgrid for a project I'm working on and I'm very impressed with its performance. One requirement I have is sorting on multiple columns. I don't fully have my head wrapped around the Dataview in Slickgrid, so maybe I'm missing something obvious, but is there a way to sort a grid on multiple columns? Even if the UI can't handle sorting by more than one, I would like to be able to call a function with the columns in order, plus ascending or descending. I was able to do this with Datatables, but it doesn't have grouping (another requirement for the project).
In the worst case, I will resort to doing the sorting on the server and serving the content back to the client statically sorted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我让它以多列排序的方式为 dataView 工作。也是最容易理解的一个。这是来自 github 中的示例,除了我必须为 dataView.sort() 传递一个参数。它总是正确的,并且您可以在函数中处理排序方向。
以防万一它对某人有帮助。
I got it working for dataView with multi-column sort in the way. Was the easiest one to understand too. This is from the example in github, except that I've to pass one more parameter for dataView.sort(). It can always be true, and you can take care of the sort direction in your function.
Just in case it helps someone.
您可以链接排序比较器来进行多列排序。 不这样做
您可以
,或者只是内联实现它。
至于在 UI 中反映排序顺序,虽然您不能直接执行此操作,但您可以通过在要排序的列定义上设置“headerCssClass”并让它们显示箭头来应用排序指示符(或者您可以通过其他方式)指示排序列)。
You can chain sort comparers to do multiple column sorting. Instead of doing
you can do
or just implement it inline.
As far as reflecting the sort order in the UI, while you can't do directly, you can apply the sort indicators by setting "headerCssClass" on the column definitions you're sorting by and having them display the arrows (or however else you're indicating sort columns).
这里有一个使用“multiColumnSort”选项的示例。
http://mleibman.github.com/SlickGrid/examples/example -multi-column-sort.html
但我认为它不起作用,因为 args.sortCols 始终是一个 1 的数组。
[编辑]
为了使其工作,我需要在单击列标题之前按住 Shift 键(恕我直言,不是很直观)
另请参阅:https://github.com/mleibman/SlickGrid/pull/276
There's an example here that uses the 'multiColumnSort' option.
http://mleibman.github.com/SlickGrid/examples/example-multi-column-sort.html
I don't think it works though, because args.sortCols is always an array of 1.
[Edit]
In order for it work, I need to hold shift before clicking on a column header (not very intuitive IMHO)
See also: https://github.com/mleibman/SlickGrid/pull/276
我花了一段时间尝试用 dataview 解决这个问题(没有 Shift 键恶作剧),我想我找到了解决方法。
使用单列排序
{multiColumnSort: false}
并将排序参数存储在闭包中。如果字段相等,则遵循前一个比较器。记住所有以前的订单。就可以了。按预期工作。
I spent a while trying to solve this with dataview (without shift key shenanigans) and I think I found the way to do it.
Use single column sort
{multiColumnSort: false}
and store the sort arguments in a closure. Defer to the previous comparitor if fields are equal.remembers all previous orders. just works. works as expected.