首页 \ 问答 \ 对Kendo Grid列/ DataSource进行多重排序 - 动态设置排序(Multiple sort on Kendo Grid columns / DataSource - set sorting dynamically)

对Kendo Grid列/ DataSource进行多重排序 - 动态设置排序(Multiple sort on Kendo Grid columns / DataSource - set sorting dynamically)

我想要完成的是当用户在kendo网格中对列进行排序时应用“自动”辅助列排序。

所以在这个JS小提琴示例中 ,如果用户按“值”排序,它也将按“名称”排序。 请注意,0会一起排序,但名称不是按字母顺序排列的。 我希望它们是按字母顺序排列的(次要排序)。

这是尝试重写数据源排序以实现此目的。 我正在使用用户的原始排序并在“SortedName”上添加其他排序。 根据记录的排序数组,它似乎很接近,但仍然无法正常工作。

关于如何实现这一目标的任何其他想法?

注意:我不希望允许用户按多列排序。 我正在使用它的真实世界示例可能有多达50多列(不幸的是),因此多种排序可能会令人困惑/不直观。 而且我希望它能在幕后完成而无需额外的用户交互。

覆盖kendo数据源sort()的示例代码:

dataSource.originalSort = dataSource.sort;
dataSource.sort = function () {
    // take the user's sort and apply sorting on an additional column
    // the sort array should look like this:
    [
        { field: "Value", dir: "asc" }, // this is what the user sorted by
        { field: "SortedName", dir: "asc" }, // and I'm adding this
    ]
    return dataSource.originalSort.apply(this, arguments);
}

What I'm trying to accomplish is to apply an "automatic" secondary column sort when a user sorts a column in a kendo grid.

So in this JS fiddle example, if a user sorts by "Value", it'll also sort by "Name". Note that the 0s are sorted together, but the names aren't alphabetical. I'd like them to be alphabetical (the secondary sort).

Here's an attempt at overriding the datasource sorting to accomplish this. I'm taking the user's original sort and the adding an additional sort on "SortedName". Based on the sorting array that's logged, it seems to be close but is still not working.

Any other ideas on how to accomplish this?

Note: I don't want to allow users to sort by multiple columns. The real world example I'm using this for can have up to 50+ columns (unfortunately), so multiple sort can get confusing / unintuitive. And I'd like it to be done behind the scenes without extra user interaction.

Example code for overriding kendo datasource sort():

dataSource.originalSort = dataSource.sort;
dataSource.sort = function () {
    // take the user's sort and apply sorting on an additional column
    // the sort array should look like this:
    [
        { field: "Value", dir: "asc" }, // this is what the user sorted by
        { field: "SortedName", dir: "asc" }, // and I'm adding this
    ]
    return dataSource.originalSort.apply(this, arguments);
}

原文:https://stackoverflow.com/questions/38757379
更新时间:2024-04-05 16:04

最满意答案

SELECT 
    o.CustomerId,
    COUNT(DISTINCT o.OrderId) AS OrderCount, 
    COUNT(oi.OrderItemId) AS OrderItemCount,
    COUNT(oi.OrderItemId) / COUNT(DISTINCT o.OrderId) avg 
FROM OrderItem oi
INNER JOIN Order o ON o.OrderId = oi.OrderId
WHERE o.CategoryId = 52 -- website sales
GROUP BY o.CustomerId 
order by COUNT(oi.OrderItemId) / COUNT(DISTINCT o.OrderId) desc

只需将加入添加到客户


SELECT 
    o.CustomerId,
    COUNT(DISTINCT o.OrderId) AS OrderCount, 
    COUNT(oi.OrderItemId) AS OrderItemCount,
    COUNT(oi.OrderItemId) / COUNT(DISTINCT o.OrderId) avg 
FROM OrderItem oi
INNER JOIN Order o ON o.OrderId = oi.OrderId
WHERE o.CategoryId = 52 -- website sales
GROUP BY o.CustomerId 
order by COUNT(oi.OrderItemId) / COUNT(DISTINCT o.OrderId) desc

Just add in the join to customer

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。