Set order attribute from ajax

Set order attribute from ajax

shermesshermes Posts: 1Questions: 1Answers: 0
edited March 2020 in Free community support

Hi,

I use serverside DataTables. Is it possible to set the "order" attribute from ajax?

$('#table').DataTable({
            "columns": [
                ...
            ],
            "proccessing": true,
            "serverSide": true,
            "ajax": {
                ...
            },
            "order": "order" ??
}

return Json(new
            {
                // this is what datatables wants sending back
                draw = draw,
                recordsTotal = total,
                recordsFiltered = filtered,
                data = table,
                order = order
            });

I want to sort a table by buttons in another view. So I sort the table on server and give the result via ajax. But of course the datatable doesn't know this order. When I go to the next page, the order is wrong again. I add the oderlist to the json result, but I don't know, how to set it in DataTable.

Thanks for help.

Best regards

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    The ordering is determined by the table, as well as the paging, and is included in the request to the server - I'm not clear how it would work if the server determines the order and passes it back to the client.

    Colin

This discussion has been closed.