jQuery DataTable - Enable/disable column filtering on hide/show after initialization dynamically

Stefhan

My first post on Stack Overflow. :)

I have a jQuery DataTable, with a custom dropdown "Hide/show columns" with checkboxes. These are working perfectly. But when I hide a column, I also want it to not be searchable. When I show it again, I want it to be searchable again. Is this possible?

Here is my code:

$('input[type="checkbox"]', $("#myHideShowDropdown")).change(function () {
    // data-column is just the number of the column
    var column = oTable.column($(this).attr("data-column")); 
    column.visible(!column.visible()); // This works

    // Here I want to to something like 
    // column.searchable(!column.searchable()) 
    // but there is no such thing
});
Gyrocode.com

SOLUTION

To toggle column filtering along with visibility, use the code below:

$('input[type="checkbox"]', $("#myHideShowDropdown")).change(function () {
   var colIdx = $(this).attr("data-column");
   var column = oTable.column(colIdx);
   var isVisible = column.visible();

   column.visible(!isVisible); 
   oTable.settings()[0].aoColumns[colIdx].bSearchable = !isVisible;

   oTable.rows().invalidate().draw(false);
});    

DEMO

See this jsFiddle for code and demonstration.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jQuery Datatable plugin not filtering on Column value

From Dev

Primefaces datatable sorting after filtering

From Dev

How dynamically change column title of dataTable jQuery plugin?

From Dev

Add extra column in jquery Datatable after calling custom PHP function on it?

From Dev

format column (value) of datatable dynamically

From Dev

format column (value) of datatable dynamically

From Dev

dataTable prevent column resizing when filtering data

From Dev

Filtering a sorted column with SelectOneMenu in PrimeFaces DataTable

From Dev

Wildcard search in primefaces datatable column filtering?

From Dev

Dash plotly Datatable column filtering or cropping

From Dev

Wildcard search in primefaces datatable column filtering?

From Dev

setPropertyActionListener not working after p:datatable filtering

From Dev

setPropertyActionListener not working after p:datatable filtering

From Dev

Ajax update of datatable from a modal after filtering

From Dev

calculating jquery datatable column

From Dev

Filtering a jquery datatable on a TR data-attribute

From Dev

jQuery DataTable with filtering for duplicates of SQL table

From Dev

jquery datatable set width upon initialization

From Dev

Is there a way to dynamically update block textures after initialization?

From Dev

Is there a way to dynamically update block textures after initialization?

From Dev

dynamically name the column in the dataTable with JSON data

From Dev

JQuery Datatable textbox column hover

From Dev

jquery datatable add column at runtime

From Dev

JQuery datatable sorting previous column

From Dev

Jquery datatable issue with column sorting

From Dev

Jquery DataTable column Filter Datepicker

From Dev

How to dynamically change datatable using jquery?

From Dev

How to Create Bootstrap Popover on JQuery DataTable Dynamically

From Dev

How to update other component AFTER filtering lazy dataTable in primefaces

Related Related

  1. 1

    jQuery Datatable plugin not filtering on Column value

  2. 2

    Primefaces datatable sorting after filtering

  3. 3

    How dynamically change column title of dataTable jQuery plugin?

  4. 4

    Add extra column in jquery Datatable after calling custom PHP function on it?

  5. 5

    format column (value) of datatable dynamically

  6. 6

    format column (value) of datatable dynamically

  7. 7

    dataTable prevent column resizing when filtering data

  8. 8

    Filtering a sorted column with SelectOneMenu in PrimeFaces DataTable

  9. 9

    Wildcard search in primefaces datatable column filtering?

  10. 10

    Dash plotly Datatable column filtering or cropping

  11. 11

    Wildcard search in primefaces datatable column filtering?

  12. 12

    setPropertyActionListener not working after p:datatable filtering

  13. 13

    setPropertyActionListener not working after p:datatable filtering

  14. 14

    Ajax update of datatable from a modal after filtering

  15. 15

    calculating jquery datatable column

  16. 16

    Filtering a jquery datatable on a TR data-attribute

  17. 17

    jQuery DataTable with filtering for duplicates of SQL table

  18. 18

    jquery datatable set width upon initialization

  19. 19

    Is there a way to dynamically update block textures after initialization?

  20. 20

    Is there a way to dynamically update block textures after initialization?

  21. 21

    dynamically name the column in the dataTable with JSON data

  22. 22

    JQuery Datatable textbox column hover

  23. 23

    jquery datatable add column at runtime

  24. 24

    JQuery datatable sorting previous column

  25. 25

    Jquery datatable issue with column sorting

  26. 26

    Jquery DataTable column Filter Datepicker

  27. 27

    How to dynamically change datatable using jquery?

  28. 28

    How to Create Bootstrap Popover on JQuery DataTable Dynamically

  29. 29

    How to update other component AFTER filtering lazy dataTable in primefaces

HotTag

Archive