Sorting orthogonal data

Sorting orthogonal data

Ralf54365Ralf54365 Posts: 3Questions: 1Answers: 0

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:

  1. the code above (following the examples here https://datatables.net/manual/data/orthogonal-data )

  2. under the line [ sort: 'sizeBytes' ], i added [ type: 'num' ] (following the examples here https://datatables.net/manual/data/types )

  3. 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

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    You need to set the type property as well: https://live.datatables.net/toyovoti/2/edit . That way DataTables will use sizeBytes 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

  • Ralf54365Ralf54365 Posts: 3Questions: 1Answers: 0

    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

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    1) I'm not sure it is explicitly stated. I'll look into improving that in the manual.

    2) Do you mean you had:

            { data: 
              {
                _: 'sizeFormatted',
                sort: 'sizeBytes',
                type: 'num'
              }
            }
    

    or

            { data: 
              {
                _: 'sizeFormatted',
                sort: 'sizeBytes'
              },
             type: 'num'
            }
    

    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 inside columns.data tells DataTable where to get the data for that orthogonal type from.

    Allan

  • Ralf54365Ralf54365 Posts: 3Questions: 1Answers: 0
    1. Thank you. The docs have been a great help!
    2. I tried the first example. The second one does indeed work, thank you. When you say "type inside columns.data tells DataTable where to get the data for that orthogonal type from"-- isn't that what 'sort' is for? In my example, 'sort' is telling datatables to get the data from 'sizeBytes', and 'type' here would be to tell datatables that it's a 'num'.

    --

    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.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    isn't that what 'sort' is for?

    At the moment DataTables has only one type for a column (which is determined based on the data that the orthogonal type 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.

    Side note: do you accept PRs?

    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

Sign In or Register to comment.