Set Sorting Priority on Button Click

Set Sorting Priority on Button Click

kraftomatickraftomatic Posts: 78Questions: 13Answers: 0
edited December 2020 in Free community support

Hi All,

I'm trying to adjust the sort priority when the buttons are clicked in the below example. When "Time" is clicked, the sort would go by fastest "Prologue" time - and then when "Points" is clicked, the sort order would return to sorting by total points.

I tried adding the "order" attribute (the two "new line of codes") on the button call, without any luck.

http://live.datatables.net/yohuluco/5/edit

            buttons: [
            {
            extend: 'colvisGroup',
            text: 'Points',
            show: [ 4, 6, 8, 10, 12 ],
            hide: [ 5, 7, 9, 11 ],
            order: [[ 4, 'desc' ]] // new line of code
          },
          {
            extend: 'colvisGroup',
            text: 'Times',
            show: [ 5, 7, 9, 11 ],
            hide: [ 4, 6, 8, 10, 12 ],
            order: [[ 5, 'desc' ]] // new line of code
                }
            ],

Thanks.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599
    Answer ✓

    The easiest way would be to call order() within the buttons-action function - you've got the if statements there so just need to slot in the ordering you want for each case,

    Colin

  • kraftomatickraftomatic Posts: 78Questions: 13Answers: 0

    Thanks Colin.

This discussion has been closed.