Datatable不显示数据,但表格中使用json对象填充数据(Datatable not showing the data but table is filled with data using j

编程入门 行业动态 更新时间:2024-10-26 02:27:25
Datatable不显示数据,但表格中使用json对象填充数据(Datatable not showing the data but table is filled with data using json object)

我使用json对象填充表格并使用表格添加行方法。 有些时候它不显示任何数据,但数据在对象中并且也添加在表中。 当我点击下一页或任何表格页面时,它开始显示数据。 DataTable屏幕有问题。

表初始化。

var oRenewalsTable = $('#RenewalsTable').DataTable({ dom: "<'row'<'col-sm-3'l><'col-sm-6'B><'col-sm-3'f>><'row'<'col-sm-12'tr>><'row'<'col-sm-5'i><'col-sm-7'p>>", "autoWidth": false, responsive: true, columnDefs: [ { orderable: false, targets: [0, 8, 9] }, { width: "1%", targets: 0 }, { width: "7%", targets: 9 }, { className: "dt-center", targets: [0,4,5,6,7,8,9] } ], order: [[1, 'asc']], buttons: [ { text: 'Validate', className: 'btn-primary', action: function (e, dt, node, config) { ValidateAllChecked(); } }, { text: 'Confirm', className: 'btn-success', action: function (e, dt, node, config) { ConfirmAllChecked(); } }, 'copy', { extend: 'excel', title: 'Excel Contract Renewal List', footer: false, exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6] } }, { extend: 'pdf', title: 'PDF Contract Renewal List ', footer: false, exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6] } }, 'colvis' ] });

使用json对象将数据添加到表格。

oRenewalsTable.row.add([ checkbox, response[i].Company, response[i].Vehicle, response[i].Serial, response[i].SIMCode, response[i].InstallationDate, response[i].Status, renewalDate, Online, confirmButton + editButton ]).draw(false);

此方法用于清除表格。

var ClearDataTable = function (tableVar) { tableVar.clear(); tableVar.draw(); };

我需要维护表分页状态,但如果我不维护表状态,它工作正常。

I am filling the table using json object and using table add row method. Some time it do not show any data but data is in object and also added in the table. When i just click on the next page or any table page its starts showing the data. DataTable screen with issue.

Table initialization.

var oRenewalsTable = $('#RenewalsTable').DataTable({ dom: "<'row'<'col-sm-3'l><'col-sm-6'B><'col-sm-3'f>><'row'<'col-sm-12'tr>><'row'<'col-sm-5'i><'col-sm-7'p>>", "autoWidth": false, responsive: true, columnDefs: [ { orderable: false, targets: [0, 8, 9] }, { width: "1%", targets: 0 }, { width: "7%", targets: 9 }, { className: "dt-center", targets: [0,4,5,6,7,8,9] } ], order: [[1, 'asc']], buttons: [ { text: 'Validate', className: 'btn-primary', action: function (e, dt, node, config) { ValidateAllChecked(); } }, { text: 'Confirm', className: 'btn-success', action: function (e, dt, node, config) { ConfirmAllChecked(); } }, 'copy', { extend: 'excel', title: 'Excel Contract Renewal List', footer: false, exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6] } }, { extend: 'pdf', title: 'PDF Contract Renewal List ', footer: false, exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6] } }, 'colvis' ] });

Add data to table using json object.

oRenewalsTable.row.add([ checkbox, response[i].Company, response[i].Vehicle, response[i].Serial, response[i].SIMCode, response[i].InstallationDate, response[i].Status, renewalDate, Online, confirmButton + editButton ]).draw(false);

This method used to clear the table.

var ClearDataTable = function (tableVar) { tableVar.clear(); tableVar.draw(); };

I need to maintain the table pagination state but if i do not maintain table state it works fine.

最满意答案

经过这么多的痛苦,我终于找到了答案,在这里张贴,如果其他人得到同样的问题。 根据clear()的数据表文档 :

如果要在将数据重新加载到数据表时保存分页状态,则首先清除表,然后使用false作为参数重新绘制表。

oRenewalsTable.clear(); oRenewalsTable.draw(false);

如果您不想在将数据重新加载到数据表时保存分页状态,那么只需清除并重新绘制表格即可。

oRenewalsTable.clear(); oRenewalsTable.draw();

并获得更多的性能只是使用:

oRenewalsTable.clear().draw(false); oRenewalsTable.clear().draw();

After so much pain at last I found the answer, posting here just if anyone else get the same problem. According to datatable documentation for clear():

If you want to save the pagination state while reloading the data to datatable then first clear the table and and redraw the table using false as a parameter.

oRenewalsTable.clear(); oRenewalsTable.draw(false);

If you do not want to save the pagination state while reloading the data to datatable then just clear and redraw the table.

oRenewalsTable.clear(); oRenewalsTable.draw();

and to gain morer performance just use:

oRenewalsTable.clear().draw(false); oRenewalsTable.clear().draw();

更多推荐

本文发布于:2023-07-24 00:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239308.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   表格   对象   json   Datatable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!