最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin4PV0评论

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far