Restrict three levels of sorting

Restrict three levels of sorting

binitbinit Posts: 5Questions: 2Answers: 0

Hi,
I am using DataTables 1.10.13
I need to restrict the sorting to only three columns,
i.e. if i click three columns then i click the column no 4 the only that particular column needs to be sorted the previous three sorted columns sorting needs to be removed.
Thanks.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,356Questions: 1Answers: 10,447 Site admin
    Answer ✓

    DataTables multi-column sorting doesn't have a limit. If you press shift while clicking a header cell to sort, it will add that column to the existing sort. If you don't press shift, it will sort that column only.

    Allan

  • binitbinit Posts: 5Questions: 2Answers: 0

    Thanks Allan,
    But,I found a way to do the same i.e.restricting to sort only three columns at a time and reset the sort when fourth column is selected.

    Thanks.

  • allanallan Posts: 63,356Questions: 1Answers: 10,447 Site admin

    How did you do it? An event listener on the order event?

    Allan

  • binitbinit Posts: 5Questions: 2Answers: 0

    Hi Allan,
    Firstly I added _fnSortListener( settings, colIdx, true, callback );
    instead of
    _fnSortListener( settings, colIdx, e.shiftKey, callback );
    which would sort on click of the header always.
    Then in the _fnSortListener function
    in condition bSortMulti i added another if condition which is

    if (sorting && sorting.length === 4 || sorting && sorting.length >= 4 ) {
                    sorting.length = 0;
                    sorting.push( [ colIdx, asSorting[0] ] );
                    sorting[0]._idx = 0;
                }
    
  • allanallan Posts: 63,356Questions: 1Answers: 10,447 Site admin

    Awesome - thanks!

    Allan

This discussion has been closed.