How customizable is the datatables server side processing model
How customizable is the datatables server side processing model
We have an existing REST API to provide paginated, sorted JSON sets of objects for an app. We would like to utilize this same endpoint to populate a datatables.net instance and do server side processing. I noticed that the server side processing expects very specific names and behaviors and I was wondering how much flexibility there is in terms of adapting existing interfaces to datatables? I don't want to change what porperties, etc my service returns but I still need this functionality. What are my options?
One thought that occured is that underneath datatables maybe I can plug into the $.ajax().then promise and do some transformation there from my format to what datatables expects? Is that possible? Can one do something similar with requests?
Thanks
This question has an accepted answers - jump to answer
Answers
Can you give an example?
Sure, at the most basic level our API supports Offset and Count arguments. Response returns a TotalCount, Count, Offset and Data array of rows.
There are many ways you could do this and none are particularly right or wrong. If the parameter names from DataTables dont match your API parameters (which I assume you cannot change) Rather than mess with DataTables code which would be an update pain. I personally would create my own proxy API which simply received the DataTables parameters and converted them to what your API requires before calling your API and then the same in reverse.
If you are using .net MVC lets say you could simply create
Sorry for the one line format but I haven't worked out how to paste code on here so it keeps its format..............
That is the very approach I was thinking. But you are saying that the only way to do this client side would involve touching the datatables source, correct? Definitely don't wanna modify it.
I cant say this 100% but I would say yes from what Ive played with.
I personally would want more control anyway over an API I couldn't change.
This way you can add authentication if required and you have more control over the fields that are being returned.