Sorting orthogonal data
Sorting orthogonal data
Test case https://live.datatables.net/toyovoti/1/edit
When sorting the test case by size, I expect "c" to be in the middle
I tried 3 approaches:
the code above (following the examples here https://datatables.net/manual/data/orthogonal-data )
under the line [ sort: 'sizeBytes' ], i added [ type: 'num' ] (following the examples here https://datatables.net/manual/data/types )
under the line [ sort: 'sizeBytes' ], i added [ type: 'sizeBytes' ]
Approach 1 and 2 didn't work, Approach 3 did. I don't know if it's by luck or not.
Could someone please explain why each of the approaches did and didn't work. I need to understand to explain this to my team. Approach 3 was just a shot in the dark and I'm trying to make sense of what 'type': 'sizeBytes" actually means, but can't wrap my head around it. Thanks
Answers
You need to set the
type
property as well: https://live.datatables.net/toyovoti/2/edit . That way DataTables will usesizeBytes
to determine what the data type for the column is, and in this case find it is numeric and thus order it as such.The other option, if you don't have the orthogonal data, is to use the file-size sorting plug-in.
Allan
thanks allan, i'm glad it works.
2 follow ups:
1) is this approach (setting the 'type' to your own custom property) explained/shown in any docs/examples? I struggled to find it
2) why doesn't type: 'num' work in this case? I would have thought explicitly setting the data type to numeric would work
1) I'm not sure it is explicitly stated. I'll look into improving that in the manual.
2) Do you mean you had:
or
The second there does work. The first (which I think is what your original message says you had) doesn't work since there is no
num
property in the data object.type
insidecolumns.data
tells DataTable where to get the data for that orthogonal type from.Allan
--
Side note: do you accept PRs? I added basic arrow-key functionality over the weekend to my datatable project and can share it, the code is super short.
At the moment DataTables has only one
type
for a column (which is determined based on the data that the orthogonaltype
resolves to). What would probably be better is to have different types for search, ordering and anything else. I haven't implemented that due to concerns over performance and backwards compatibility. It might happen one day though.Sure do! They need to be in scope though - for example I wouldn't add arrow key navigation to DataTables since KeyTable exists. Can you link to an example perhaps?
Allan