Individual column searching on specific columns, DataTable

CSharpNewBee

I've seen examples of how to apply individual column searches for each column of a DataTable either using text box, or drop down menus containing the returned values per column. However, I've not yet come across any mechanism to only apply them to specific columns. For example, using the below would apply the search text box to all except coloumn zero:

$('#DataTable tfoot th:gt(0)').each(function () {
    var title = $(this).text();
    $(this).html('<input type="text" 
    style="width:120px;"  placeholder="search ' + title + '" />');
});

But, how would I then also remove it from column 6 & 7 for example?

* UPDATE * This question relates to server side processing only. Should of stated that earlier.

Sylvain Guilbert

I personnaly use column definition in combination with iniComplete callBack. In this example two types of search, you can add as many different searches (even no search)

$('#table').DataTable({
            "ajax": {
                "url": "/flux/ajax",
                "dataSrc": "data",
                "scrollX": true
            },
            "columns": [                    
                {className: "select", "title": "Status", "data": "stat"}
                {className: "text", "title": "Libellé", "data": "Lib"}}
            ],
            initComplete: function () {

                this.api().columns().every(function () {
                    var column = this;
                    if ($(column.header()).hasClass('select')) {
                        console.log(column);
                        var select = $('<select><option value="">' + $(column.header()).html() + '</option></select>')
                                .appendTo($(column.header()).empty())
                                .on('change', function (e) {
                                    e.stopImmediatePropagation();
                                    var val = $.fn.dataTable.util.escapeRegex(
                                            $(this).val()
                                            );
                                    column
                                            .search(val ? '^' + val + '$' : '', true, false)
                                            .draw();
                                    return false;
                                });
                        column.data().unique().sort().each(function (d, j) {
                            select.append('<option value="' + d + '">' + d + '</option>');
                        });
                    } else if ($(column.header()).hasClass('text')) {
                        var text = $('<input type="text" placeholder="' + $(column.header()).html() + '" />')
                                .appendTo($(column.header()).empty())
                                .on('keyup change', function () {
                                    var val = $.fn.dataTable.util.escapeRegex(
                                        $(this).val()
                                        );
                                    if (column.search() !== this.value) {
                                        column
                                                .search(val)
                                                .draw();
                                    }
                                    return false;
                                });

                    }

                });
            }
        });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to disable searching in specific DataTable columns?

From Dev

Datatable Colvis : enable individual column searches for columns which are initially hidden

From Dev

DataTable - Why can't I get individual column searching (select inputs) working?

From Dev

Jquery datatable individual searching excluding unsearcable

From Dev

not able to filter the individual column in datatable

From Dev

jQuery Datatables: Individual column searching not working

From Dev

datatables - Individual column searching with accent neutralise

From Dev

datatables - Individual column searching with accent neutralise

From Dev

How can I add filteration drop down on a specific column in datatable plugin along with searching and sorting

From Dev

Count specific datatable columns

From Dev

R datatable: Hide search box for individual columns

From Dev

Parsing a database column into individual columns

From Dev

Datatable function for specific column

From Dev

R: matching columns between individual tables and adding value of specific another column

From Dev

Searching a specific columns of a table for not matching items

From Dev

Searching a specific columns of a table for not matching items

From Dev

Extracting Specific Columns from a DataTable

From Dev

Extracting Specific Columns from a DataTable

From Dev

Pandas dataframe - transform column values into individual columns

From Dev

Transform column values into individual columns in R

From Dev

Transform column values into individual columns in R

From Dev

Dropdown filter on specific column in DataTable

From Dev

How to add search to some individual columns of DataTable in the footer?

From Dev

Searching for a value in a DataTable column returns empty when the value exists

From Dev

Searching individual words in a string

From Dev

JSF Primefaces datatable match mode for global filter (not individual column)

From Dev

Copy specific columns from one DataTable to another

From Dev

PrimeFaces dataTable with variable columns and specific editable cells

From Dev

Copy specific columns from one DataTable to another

Related Related

  1. 1

    How to disable searching in specific DataTable columns?

  2. 2

    Datatable Colvis : enable individual column searches for columns which are initially hidden

  3. 3

    DataTable - Why can't I get individual column searching (select inputs) working?

  4. 4

    Jquery datatable individual searching excluding unsearcable

  5. 5

    not able to filter the individual column in datatable

  6. 6

    jQuery Datatables: Individual column searching not working

  7. 7

    datatables - Individual column searching with accent neutralise

  8. 8

    datatables - Individual column searching with accent neutralise

  9. 9

    How can I add filteration drop down on a specific column in datatable plugin along with searching and sorting

  10. 10

    Count specific datatable columns

  11. 11

    R datatable: Hide search box for individual columns

  12. 12

    Parsing a database column into individual columns

  13. 13

    Datatable function for specific column

  14. 14

    R: matching columns between individual tables and adding value of specific another column

  15. 15

    Searching a specific columns of a table for not matching items

  16. 16

    Searching a specific columns of a table for not matching items

  17. 17

    Extracting Specific Columns from a DataTable

  18. 18

    Extracting Specific Columns from a DataTable

  19. 19

    Pandas dataframe - transform column values into individual columns

  20. 20

    Transform column values into individual columns in R

  21. 21

    Transform column values into individual columns in R

  22. 22

    Dropdown filter on specific column in DataTable

  23. 23

    How to add search to some individual columns of DataTable in the footer?

  24. 24

    Searching for a value in a DataTable column returns empty when the value exists

  25. 25

    Searching individual words in a string

  26. 26

    JSF Primefaces datatable match mode for global filter (not individual column)

  27. 27

    Copy specific columns from one DataTable to another

  28. 28

    PrimeFaces dataTable with variable columns and specific editable cells

  29. 29

    Copy specific columns from one DataTable to another

HotTag

Archive