Override order-function

Override order-function

pingvispingvis Posts: 5Questions: 1Answers: 0

Currently, we're using the datatables to display large amounts of data. The data is coming from an RESTful API (directly with AJAX, not JSONP), but the format the API outputs the data doesn't match the required format datatables needs, so it's impossible to use the ajax-functions directly.

Instead, we create an empty table, execute an AJAX-call on the API and use the addRow function tot add the returned rows. The amount of items coming from the API can be very large (up to 100.000 items), so it's not wanted to load ALL items. So we call the API and request the latest 50 items and add them. But when a column is clicked to sort the data, only the 50 loaded items are being sorted... Sorting an column should however call the API and give again 50 items in the correct order to prevent huge request. Unfortunately I didn't manage to override the default sort functions.

With $(table).on( 'order.dt', function () { ... }); i'm able to catch the order-function, but i'm not able to override it by using a return false; or someting. Any ideas how to get this done without having to write an in-between PHP script catching the default datatables-ajax URL's, converting them into an API-request, getting the data and converting it back to an datatables-format?

Answers

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    The order event is not cancellable. Nor can it be used to override the sort - it is just a notification that the sort has happened.

    Are you client-side or server-side processing the data? Can you link to a test page showing the issue please.

    Allan

  • pingvispingvis Posts: 5Questions: 1Answers: 0

    I'm sorry, but I don't have a online test-location at the moment. The "problem" here is that the datatables object does too much for me. Basicly, the only thing I want is a callback function giving me an event like: "Hey, someone changed the order of the table, so... go update it!". The column-header may change automaticly based on the new ordering, but the data should not be ordered based on the current data. I need full control of what URL I will call, so I can add rows manually based on the given response from the API we're talking with...

  • pingvispingvis Posts: 5Questions: 1Answers: 0

    I already tried to catch the $(table).on('order.dt', function () { ... }, then remove all rows with $(table).DataTable().clear(); and settings $(table).off('order.dt'); to prevent loops, then request new data from the API, add that data to the table using addRow, but somehow, the headers seems to get confussed by this...

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    If you want to control the ordering yourself you would need to use a plug-in ordering method. As I say, there is no way to cancel the order externally - the order event is just a notification to let you know that an order has happened.

    Allan

This discussion has been closed.