简体   繁体   English

调用页面事件后如何刷新DataTables?

[英]How to refresh DataTables after call to page event?

Here is my scenario ... 这是我的情况...

I am using pagination with DataTables. 我正在使用DataTables分页。 My first column is css styled based upon data that is passed in. So, I display the correct colored icon for the property of the item in the table. 我的第一列是基于传入数据的css样式。因此,我在表中为该项目的属性显示正确的彩色图标。 Everything on page 1 displays correctly. 第1页上的所有内容均可正确显示。 Just doing the basics, everything on further pages does not get displayed because it is removed from the DOM at that time. 仅做基础操作,其他页面上的所有内容都不会显示,因为那时它已从DOM中删除。

So, I did $('#my_id').on('page.dt', function() {perPageFunctionCall();}).dataTable(so on an so forth)}; 所以,我做了$('#my_id').on('page.dt', function() {perPageFunctionCall();}).dataTable(so on an so forth)}; to call a function which selects the correct colored flag. 调用选择正确颜色标记的函数。

When I click on page 2, nothing gets updated. 当我单击第2页时,没有任何更新。 I click on page 1 again and it redisplays the 1st page correctly. 我再次单击第1页,它正确地重新显示了第一页。 I click on page 2 a second time now and it displays everything correctly this time. 我现在第二次单击页面2,这次它正确显示了所有内容。

So what is causing the display not to update with my new css the 1st trip but to display properly on subsequent trips? 那么,是什么原因导致显示不随着我的新CSS在第一次旅行时更新,而是在随后的旅行中正确显示? Is there someway to refresh the element or the data table after I am done with my css manipulation? 在完成CSS操纵之后,是否可以通过某种方式刷新元素或数据表?

Well it is one of two things: 嗯,这是两件事之一:

Either it is 要么是

1: I added 1:我加了

    .on( 'order.dt',  function () { perPageFunctionCall(); } )
    .on( 'search.dt', function () { perPageFunctionCall(); } )

in addition to my page function call. 除了我的页面函数调用。

But more likely everyone's favorite reason: 但更可能是每个人最喜欢的原因:

2: Caching 2: 缓存

In either case, it does work flawlessly now as expected. 无论哪种情况,它现在都可以正常工作。

for refresh resp. 刷新刷新。 table : 表:

var path = "/server_processing.php";

var dt = $('#tableid').DataTable();
dt.clear();
dt.draw();
dt.ajax.url(path).load()

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

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