最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to reload datatable keeping the page and filtering searching if exist without refreshing the page? - Stack Over

programmeradmin4浏览0评论

I'm using dataTable plugin to show data from Database , The table looks like:

name   location     actions
jack   New York   Edit , Delete
john   London     Edit , Delete
...    ...        Edit , Delete

The Adding/Editing/Deleting functions are working well , But I have to refresh the page to see the results.

How to reload the table but keep the previous parameters like page and searching if they exist?

I'm using dataTable plugin to show data from Database , The table looks like:

name   location     actions
jack   New York   Edit , Delete
john   London     Edit , Delete
...    ...        Edit , Delete

The Adding/Editing/Deleting functions are working well , But I have to refresh the page to see the results.

How to reload the table but keep the previous parameters like page and searching if they exist?

Share Improve this question asked Mar 9, 2018 at 22:10 jackjack 1512 silver badges12 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You can use:

table.ajax.reload(null, false);

The second parameter is resetPaging, if is true will reset the datatable to default, if is false will hold the current paging position. The first parameter is a callback function.

For more information, see: https://datatables/reference/api/ajax.reload()

If using and XHR data source with DataTables:

// Init DataTables with XHR source
var table = $('#myTable').DataTable({
  ajax: "my/xhr/data/source"
});

// Reload the table every 30 seconds 
setInterval( function () {
  table.ajax.reload();
}, 30000);

Of course, you could reload under a refresh button on after you add/edit/delete rows in your XHR callbacks.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论