filter field in column header with sorting

filter field in column header with sorting

sargemisargemi Posts: 4Questions: 1Answers: 0

Link to test case: https://live.datatables.net/sargemi/1/edit

Description of problem: We have a filter field in a column header with sorting, when selecting the field with a click the sorting of the table is performed. How can the sorting be cancelled when clicking on the filter element?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,629Questions: 26Answers: 5,010

    Your test case doesn't run due to errors listed in the browser's console.

    You can try using stopPropagation is described in this thread. Or create two header rows like this example:
    https://live.datatables.net/saqozowe/2441/edit

    Kevin

  • allanallan Posts: 63,966Questions: 1Answers: 10,547 Site admin

    I modified your example a little to run: https://live.datatables.net/sargemi/2/edit (it wasn't loading correctly in Firefox).

    It doesn't order when I click in the header select at the moment. However, I'd very much recommend you put the select in a second row in the header and use orderCellsTop to have sorting on the top cells only.

    Allan

  • sargemisargemi Posts: 4Questions: 1Answers: 0
    edited February 3

    @kthorngren OrderCellsTop is deprecated :(
    @alla stoppropagation stop the search but only do order event, and i don't want "2 headers".
    Thnks

  • sargemisargemi Posts: 4Questions: 1Answers: 0

    I add the example without errors
    https://live.datatables.net/sargemi/5/edit

  • kthorngrenkthorngren Posts: 21,629Questions: 26Answers: 5,010
    Answer ✓

    OrderCellsTop is deprecated

    I suspect that since Allan mentioned it that he is reconsidering deprecating orderCellsTop based on other feedback. I don't want to speak for Allan though :smile:

    Updated your test case to use stopPropagation:

    $('thead select', table.table().container()).on('click', function (evtObj) {     
        evtObj.stopPropagation();
    });   
    

    https://live.datatables.net/sargemi/9/edit

    Kevin

  • sargemisargemi Posts: 4Questions: 1Answers: 0

    This way it worked, I'm going to adapt my code to it

    Thank you very much @kthorngren
    Thanks anyway @allan

  • allanallan Posts: 63,966Questions: 1Answers: 10,547 Site admin

    I suspect that since Allan mentioned it that he is reconsidering deprecating orderCellsTop based on other feedback. I don't want to speak for Allan though

    Spot on!

    Allan

Sign In or Register to comment.