Using Datatables and savestate

133 0 0 0

Last Updated : 2021-04-12 22:12:58

When using datatables and made a filter, then navigated a way from the current page for editing or somthing like this as went back to find out that the filteration you have done already is gone, if you want to preserve this state when you comeback, the solution is simple in datatable like this:

Here is the main implementation of the datatables in mycase:


$("#itemsTable").DataTable({
processing: true,
serverMethod: 'get',
ajax: {
url: "{{ url('admin/bills') }}"
},
columns: myJSON
});


Now, we need to add this :  serverSide: true, so that the code becomes :


$("#itemsTable").DataTable({
processing: true,
serverMethod: 'get',
stateSave: true, //This will reserve the state when you come back to the same page again
ajax: {
url: "{{ url('admin/bills') }}"
},
columns: myJSON
});

That's it 😄
-

Mohammed Anwar

Mohammed Anwar

Experienced technical lead PHP, MySQL and Laravel Developer for 15+ years, with proven ability to develop and create high-quality and optimized web applications. Great ability to build and optimize database design, schema and queries. Versed programing trainer and instructor delivering web courses and helping others to get into the field in a timely manner. Fast and eager learner for new technologies .