简体   繁体   English

jQuery 数据表:Ajax 与 c# 加载

[英]jQuery Datatables: Ajax vs c# loading

Finally got datatables to properly retrieve, then format data for an application I am writing and after looking at the code, I began to wonder, is it better to allow datatables to retrieve the raw data and format it in the javascript of the view, or format the table data in a class before it's handed back to datatables?最后让数据表正确检索,然后为我正在编写的应用程序格式化数据,在查看代码后,我开始怀疑,允许数据表检索原始数据并在视图的 javascript 中对其进行格式化会更好,还是在将表数据交回数据表之前格式化类中的表数据?

My first instinct would to be to allow the class to do it, but, being new to jQuery, I was wondering if that WAS the way, then why would datatables have that much client side capability.我的第一直觉是允许类这样做,但是,作为 jQuery 的新手,我想知道这是否是这种方式,那么为什么数据表具有如此多的客户端功能。

Anyone have pros or cons for either way?任何一种方式都有优点或缺点吗?

Without knowing more, I would recommend formatting and styling on the client side.在不知道更多的情况下,我建议在客户端进行格式化和样式设置。 Here are a few thoughts...这里有一些想法......

  • With a website/client app, reducing the amount of traffic / data sent to the client from the server will be beneficial.使用网站/客户端应用程序,减少从服务器发送到客户端的流量/数据量将是有益的。
  • Centralizing the logic for any styling will benefit you in the long term by reducing the complexity of your site and make it easier to change later.通过降低站点的复杂性并使以后更容易更改,将任何样式的逻辑集中起来将从长远来看使您受益。
  • Styling on the client-side will allow you to serve multiple different types of clients with the same server-side code (ie: native mobile app and web browsers).客户端的样式将允许您使用相同的服务器端代码(即:本机移动应用程序和 Web 浏览器)为多种不同类型的客户端提供服务。
  • Common practice is to provide the data you wish to have displayed in a standard format such as JSON, then format the content to fit the client device in the client-side code.通常的做法是以标准格式(例如 JSON)提供您希望显示的数据,然后在客户端代码中格式化内容以适合客户端设备。

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

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