How to have sort and select filters in different header rows?

How to have sort and select filters in different header rows?

SansuiSansui Posts: 7Questions: 2Answers: 1

I'm following the example found here - https://datatables.net/examples/api/multi_filter_select.html

We have two identical table header rows in the thead, wanting one for sort and one for filters.

We didn't want the select filters in the footer, so changed it to column.header() and tried using orderCellsTop, but what happens is both the sort and the filter are applied to the same row no matter what.

Any recommendations on how to apply the sort to the second table header?

This question has accepted answers - jump to:

Answers

  • SansuiSansui Posts: 7Questions: 2Answers: 1

    https://jsfiddle.net/LLzajqtv/ here's a fiddle using the sample data as an example

  • allanallan Posts: 63,783Questions: 1Answers: 10,511 Site admin
    Answer ✓

    Rather than using column().header() you need to use jQuery to address the second row. The DataTables API currently only allows the primary header cell for the column to be accessed through it.

    Allan

  • SansuiSansui Posts: 7Questions: 2Answers: 1

    I think this fiddle achieves what I'm looking for. https://jsfiddle.net/wwhe7k20

    Filter at top, sort on bottom.

  • SansuiSansui Posts: 7Questions: 2Answers: 1

    Also wanted to remove some filters, so this fiddle shows how to do that for anyone in the same boat - https://jsfiddle.net/wwhe7k20/2/ - using not(":eq(2),:eq(3),:eq(4)") to remove specific columns

  • allanallan Posts: 63,783Questions: 1Answers: 10,511 Site admin
    Answer ✓

    Great - thanks for posting up the fiddles for others :-)

    Allan

This discussion has been closed.