How to sort a column which contains server-side generated values other than database values
How to sort a column which contains server-side generated values other than database values
Hi,
I am using Datatables for one of my page to display data.I am using server-side scripting to display the table.
In my HTML I have 17 columns.Some columns are fetched from the DB and others are created in the script and contain some mathematical calculations .Those are not present in any of DB fields.
My problem is that I need to sort those columns that have generated values. But this is not possible because serverSide sends the name of the column that i need to sort and in the serverside script i apply the order by in the query, but those are not present in the DB.
Does anyone knows how I can keep the serverSIde option and sort those generated columns? Or is this possible only on the client side?
Answers
Hi @vatco ,
If you've enable
serverSide
, then all sorting/paging/filtering is the responsibility of the server, I'm afraid, it's not possible to have one column sorted by the client, and the rest sorted by the server.How many rows are in your dataset? If it's not too many (say in the low thousands at most) you could use
ajax
to get the data (see examples here), but the client would still be responsible for the sorting/paging/filtering.Hope that helps,
Cheers,
Colin
Hi @colin ,
Unfortunately my dataset has over 1 milion records, and depending of the client the query will return between 10.000 and 20.000 records. I had implemented the ajax before with all kind of filters so I could limit the informations returned with every call. But now I need to display some raw informations without any filters, so, loading 20.000 records takes 3 mins to load. All the generated columns and calculations are done on the serverside script in the loop.
Bellow there is an example of how i handle this in the serverside script:
As you can see in the object I have number and balance that are generated in the loop.These are the columns that i need to sort and i could't find any solution yet.
Many thanks!
Hi @vatco ,
Yep, unfortunately you're going to need to do that in your server script, there's no other way I'm afraid.
Cheers,
Colin