Order
Order
ZeoNish
Posts: 12Questions: 3Answers: 0
Can I do the sorting this way?
Cols
id | user name | date
1 | User 1 | Date
2 | User 2 | Date
3 | User 3 | Date
5 | User 1 | Date
6 | User 1 | Date
7 | User 2 | Date
8 | User 1 | Date
need
User 1 First order
1 | User 1 | Date
5 | User 1 | Date
6 | User 1 | Date
8 | User 1 | Date
and asc/desc other rows
2 | User 2 | Date
3 | User 3 | Date
7 | User 2 | Date
Thx.
Answers
I'm not quite following the rules for the sort applied I'm afraid. Could you elaborate a bit?
Allan
all rows where collumn "user name" == User 1 upper in ordering
demo my columns
id | user name | date
data rows
1 | User 1 | Date
2 | User 2 | Date
3 | User 3 | Date
5 | User 1 | Date
6 | User 1 | Date
7 | User 2 | Date
8 | User 1 | Date
need all rows where collumn "user name" == User 1 upper in ordering
order column "id" ASC and all collumn "user name" == User 1 upper in ordering
User 1 First order
1 | User 1 | Date
5 | User 1 | Date
6 | User 1 | Date
8 | User 1 | Date
and asc/desc other rows
2 | User 2 | Date
3 | User 3 | Date
7 | User 2 | Date
https://datatables.net/reference/option/order
But I don't think you want that. You seem to want completely separate ordering depending on the "user" being User 1 or some other user.
You can't do that client side I am afraid.
I did something similar on the server using the "postGet" event and then manipulating $data which can be passed by reference.
https://editor.datatables.net/manual/php/events#Get
On the client I turned off the automatic ordering like this:
Yeah, I'm still not 100%. Is you want "User 1" to be the primary sort, then id, but if not "User 1" then "id" should be the primary sort? Not sure I've ever encountered that before.
You'd need to have a column that contains both data points and have a custom data type sort function that would do that. Perfectly possible, but a little bit of coding required.
Allan
This should do the job on the server:
Use that with this on the client side:
Very clever - like it! Just make sure ordering is disabled or set to
[]
on the client-side so DataTables doesn't resort.Allan
Thanks Allan! I think doing special formatting server side is a lot easier than doing it with Java Script in the browser. And it's probably faster, too. In this example I add a summation row to the data table inside field type "datatable". This wouldn't work with client side ordering just like in the example above: Client side ordering would always put the summation row in the wrong position.
I normally only return formatted values from the server. Here I also read them unformatted to be able to order them and sum them up. Afterwards I simply unset the "helper fields".
What I really like is the flexibility that this provides: If I didn't have this I would need to do this all outside of Editor. It's great that I can keep using Editor even for "special cases" like this one.
And this is what it looks like in reality inside the Editor modal.
Yup - that is very nice and a great use case / example. Thank you!