This article is a mirror article of machine translation, please click here to jump to the original article.

View: 18687|Reply: 0

[Jquery] Jquery dataTable dynamically loads data for ajax requests

[Copy link]
Posted on 11/2/2015 6:43:40 PM | | | |


Front Desk Code:

  1. <table id="example1" class="table table-bordered table-striped">
  2.                             <thead>
  3.                                 <tr>
  4.                                     <th>站点名称</th>
  5.                                     <th>站点域名</th>
  6.                                     <th>认证方式</th>
  7.                                 </tr>
  8.                             </thead>
  9.                             <tbody id="aaaa">
  10.                                 
  11.                             </tbody>
  12.                             <tfoot>
  13.                                 <tr>
  14.                                     <th>Rendering engine</th>
  15.                                     <th>Browser</th>
  16.                                     <th>Platform(s)</th>
  17.                                 </tr>
  18.                             </tfoot>
  19.                         </table>
Copy code
  1. $('#example1').dataTable({
  2.                 "bPaginate": true,
  3.                 "bLengthChange": false,
  4.                 "bSort": true,
  5.                 "bInfo": true,
  6.                 "bAutoWidth": false,
  7.                 "bFilter": true,
  8.                 "ajax": '/Login/Data',
  9.                 "columns": [
  10.                     { "data": "name" },
  11.                     { "data": "bewrite" },
  12.                     { "data": "Descrip{过滤}tion" }
  13.                 ],
  14.                 "oLanguage": {
  15.                     "sLengthMenu": "每页显示 _MENU_ 条记录",
  16.                     "sZeroRecords": "对不起,查询不到任何相关数据",
  17.                     "sInfo": "当前显示 _START_ 到 _END_ 条,共 _TOTAL_ 条记录",
  18.                     "sInfoEmtpy": "找不到相关数据",
  19.                     "sInfoFiltered": "数据表中共为 _MAX_ 条记录)",
  20.                     "sProcessing": "正在加载中...",
  21.                     "sSearch": "搜索",
  22.                     "sUrl": "", //多语言配置文件,可将oLanguage的设置放在一个txt文件中,例:Javascrip{过滤}t/datatable/dtCH.txt
  23.                     "oPaginate": {
  24.                         "sFirst": "第一页",
  25.                         "sPrevious": " 上一页 ",
  26.                         "sNext": " 下一页 ",
  27.                         "sLast": " 最后一页 "
  28.                     }
  29.                 }
  30.             });
Copy code
Background Code:

  1. [HttpGet]
  2.         public JsonResult Data()
  3.         {
  4.             List<BLL.Models.GetDictionary> list = BLL.Until.GetUserInfo.GetUser();
  5.             return Json(new { data = list },JsonRequestBehavior.AllowGet);
  6.         }
Copy code
Note that dataTable defaults to get requests, post will not request data, and then json needs to set JsonRequestBehavior.AllowGet to allow all get request methods.

Finally, the official documentation is attached: https://datatables.net/examples/ajax/




Previous:Bootstrap Datatable is a simple basic configuration
Next:Because there is no implicit conversion between &lt;null&gt; and System.DateTime
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com