Search by two columns

Search by two columns

gruchaapgruchaap Posts: 2Questions: 1Answers: 0

Hi all,
I want to search table by only two columns. E.g. Initial search searches in all columns, I just want to search by two columns.
When I use following code:
dataTable.columns(1,7)
.search(this.value)
.draw();
the search text must be present in both columns to be displayed. I want to display it even if it exists in one of the columns.
Can anyone help?

Thanks,
gruchaap

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Answer ✓

    Two options:

    1. Disable search for all other columns using columns.searchable
    2. Use a custom search plug-in

    Allan

  • gruchaapgruchaap Posts: 2Questions: 1Answers: 0

    Thank you! SOLVED thanks to you.
    Changes in code:
    I've changed searching to initial which searches all columns:

    dataTable
        .search(this.value)
        .draw();
    

    And set columns which I don't want to be search in initTable:

    "columnDefs": [
    {
        "targets": [2,5],
        "searchable": false
    }]
    
This discussion has been closed.