简体   繁体   中英

Disable server-side processing for sort

I'm using of DataTables for show information in a table and I've enabled server-side load (I need that just for load data and pagination) and I don't need to search or sort by server side and I need default search and sorting (jQuery) for my table.

How can I do that ?

 var table2 = $('#datatable-buttons2').DataTable({ "serverSide": true, "processing": true, "asSorting": ['desc', 'asc'], "ajax": { 'type': 'POST', 'url': 'test.php?nowsearch=1', 'data': { inputaz: $("#inputaz").val(), inputta: $("#inputta").val(), inputkey: $("#inputkey").val() } }, "columns": [{ "data": "group_name" }, { "data": "sender" }, { "data": "date" }], }); 

Maybe you can do this, customizing data retrieved in Javascript, but this is not useful .

If you sort your items in clientside with serverSide: true , it will be sorted the current retrieved data only, not based in all dataset in your database (if you actually limit results, if you don't, then use directly serverSide: false witch will retrieve all records).

For example, if you have 1000 records, you only get the data of first 10 of then only, not all (10/25/50/100). If you sort locally by age , it will sorted the retrieved 10. Then, if you go to the next page, you will notice the 2nd page is not sequential from the 1st page.

That's why you must to code your sorting/search in your back-end language when you use serverSide: true : in there you will sort first and then you return 10 records sorted.

That's the idea for this option.

Anyway... You can have pagination for client-side ( serverSide: false ) too by using paging option . But you need to be aware about performance.

In short, if you will handle many records, you should keep using server-side and code the sorting/search/pagination/etc from your back-end an return corresponding data. Is not so hard. You can play with parameters sent to achieve this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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