简体   繁体   English

Web应用中的排序

[英]Sorting in Web Applications

With the increasing popularity of powerful client side javascript widgets, I am curious on when is the best time to handle the sorting of data strictly on the client side, making use of widgets such as those found in YUI, and when to make a request to the backend and have it handle the sorting via a DB query or other means.随着强大的客户端 javascript 小部件的日益普及,我很好奇什么时候是在客户端严格处理数据排序的最佳时间,使用 YUI 中的小部件,以及何时发出请求后端并让它通过数据库查询或其他方式处理排序。

It depends on the amount of data - the best thing to do is to test and see which is faster.这取决于数据量 - 最好的办法是测试并查看哪个更快。

It really depends what you're sorting, whether the client will require all of the data or only a sorted subset at any one time, and how expensive the sort actually is.这实际上取决于您要排序的内容,客户端是否需要所有数据或仅需要排序的子集,以及排序的实际成本。

Personally, I would probably sort it on a postback.就个人而言,我可能会在回发时对其进行排序。 But if all your data is displayed on the page, then sorting via JS might provide a more responsive UI.但是如果你所有的数据都显示在页面上,那么通过 JS 排序可能会提供一个响应更快的 UI。

Another thing to think about is if you want to do a grouped sort or sort by a value and then translate that value into something human readable (ie unixtime), then it might be quicker and simpler to sort on the server.另一件要考虑的事情是,如果您想进行分组排序或按值排序,然后将该值转换为人类可读的内容(即 unixtime),那么在服务器上进行排序可能会更快更简单。

Except for exceptional cases, sort in the browser.除特殊情况外,请在浏览器中排序。 Exceptional cases would be irrationally long lists, strange sorting rules requiring a host resource, insufficient javascript coding skills, etc. But there's not much to be gained from unnecessary round-tripping.例外情况是不合理的长列表、需要主机资源的奇怪排序规则、javascript 编码技能不足等。但是从不必要的往返中没有什么好处。

Very seldom does it make sense to download to the user more data than can comfortably be scrolled;向用户下载比舒适滚动更多的数据很少有意义; and lists of this size should sort quite comfortably in the browser.并且这种大小的列表在浏览器中应该可以很舒服地排序。

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

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