Targeting a column filter if a column before is not visible

Targeting a column filter if a column before is not visible

greenman123greenman123 Posts: 10Questions: 5Answers: 0
edited January 17 in Free community support

I recently asked this question:

https://datatables.net/forums/discussion/54071/how-to-clear-a-filter-upon-column-visibility-button-click#latest

This appeared to work - BUT if I have column visibility enabled and one of the columns before the above scenario of filtering the column are hidden then the target to reset the filter won't work because it is taking into account the invisible column in the numbering which I am referencing.

Is there a way to get this to work? I have tried targeting like this:

$('#example thead tr:eq(1) th:visible:eq('+column+') input').val('')

But this doesn't work - I need either a way of targeting visible inputs or to target the filter input css ID but I can't seem to be able to match the filter name e.g. #filter-customer on the input to the column number being passed back from column-visibility.dt

As my columns are in DataTables the ideal would be to get the column name back rather than the ID, anyway to do that?

I tried:

table.columns(column).name()
and
table.column(column).name()

with no luck.

This question has an accepted answers - jump to answer

Answers

  • greenman123greenman123 Posts: 10Questions: 5Answers: 0

    PS I also thought I could use the th's data-column-index="3" but this number moves when colReorder is used so doesn't match the column index response.

  • colincolin Posts: 5,549Questions: 0Answers: 970
    Answer ✓

    Hi @greenman123 ,

    Good spot, I never considered that. This here will resolve that - it gets the index for the node.

                var idx = $(table.column(column).header()).index();
                $('#example thead tr:eq('+idx+') th:eq(1) input').val('')
    

    Cheers,

    Colin

Sign In or Register to comment.