orderMulti when columnDef has orderData set

orderMulti when columnDef has orderData set

vol7ronvol7ron Posts: 43Questions: 11Answers: 0

http://live.datatables.net/lujuvuwu/5/edit?js,output

  1. Sort by Age
  2. Shift+Click the Name field to also apply sort by it
  3. Shift+Click the Name field again to change the sort direction

Notice there was no movement. I believe this is due to the configuration of the applied orderData, since Age (column 3) is configured with orderData: [3,0].

I'm curious how to break the column definitions when multiOrder is engaged. In the example the columns are sorting how I expect them to by default. Sorting any field would first sort that field, then sort by the person's name. But if I shift+click any other field, I'd only want to sort by the columns involved in the multisort, ignoring the initial orderData.

Does this make sense? If so, is there a native way to implement this type of behavior?

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @vol7ron ,

    That's not possible, I'm afraid. The orderData would always have an additional sort of that first column, the name, so that's why you're seeing the behaviour you are.

    An alternative perhaps would be to use the order, and add an additional order on with order(). You would need a check to ensure the event doesn't loop by also doing it with your additional one, but that could be a global flag that gets set.

    Hope that helps,

    Cheers,

    Colin

  • vol7ronvol7ron Posts: 43Questions: 11Answers: 0

    @colin Thank you for your reply.

    The interesting thing is I think this was not an issue in older versions of DataTables (1.9) -- atleast, the behavior always worked as expected. I'm trying to isolate what the difference was, but I've made so many changes through the version upgrade, that I'm not exactly user. I think it has something to do with a sortData

    I've made so many changes that it would take some time to isolate the differences, though I started to confuse myself because the old version contained mixtures of various sort/order fields. Consider these:

      aaSorting: [[ 1,'desc'], [0,'asc']],
      aDataSort: [ 2, 1],
      order: [[1,'asc']],
      aoColumns: [ null, null, { orderData: [2,1] }
    
This discussion has been closed.