最新消息:前端博客、web前端博客、Angularjs、javascript、jQuery、HTML5、CSS3

表格插件dataTable使用篇

JavaScript AZ 1678浏览 0评论

很多时候,我们显示的数据都是从后返回的,数据格式也是约定好的。但是后台人员为了节省资源,提高性能,读取数据时会把空数据不输出。这种情况下,使用dataTable插件就会出现错误提示,如(DataTables warning: table id=dataList – Requested unknown parameter ‘nowSn’ for row 0. For more information about this error, please see https://datatables.net/tn/4)。所以要求我们在绑定前先做一下数据判定,数据为null或undefined时补完全。

  1. for (var i = 0; i < tableData.length; i++) {
  2. if (tableData[i]['avatar'] == null) {
  3. tableData[i]['avatar'] = "";
  4. }
  5. if (tableData[i]['userName'] == null) {
  6. tableData[i]['userName'] = "";
  7. }
  8. if (tableData[i]['email'] == null) {
  9. tableData[i]['email'] = "";
  10. }
  11. if (tableData[i]['phone'] == null) {
  12. tableData[i]['phone'] = "";
  13. }
  14. if (tableData[i]['nowSn'] == null) {
  15. tableData[i]['nowSn'] = "";
  16. }
  17. }

或者是

  1. {
  2.                                 "data": "companyName",
  3.                                 "render": function(data, type, row, meta) {
  4.                                     return (row.companyName === undefined) ? '' : row.companyName;
  5.                                 }
  6.                             }

转载请注明:TUTERM.COM » 表格插件dataTable使用篇

如果您觉得本文的内容对您的学习有所帮助,您可以支付宝(左)或微信(右):
alipay weichat

您必须 登录 才能发表评论!