Jovs
Jovs

Reputation: 892

how to get the searched data in datatable but not show it

I want to check if the data is already exist in datatable in certain column but I don't know how to do it.

Heres what I tried

var issueData = $('#table').DataTable().column(2).search($('input[name=search]').val()).rows({search: 'applied'}).data().toArray();
          if(issueData == '')
          {
            var data = [];

            data.push(rowData[0]);
            data.push(rowData[3]);
            data.push(rowData[2]);
            data.push(rowData[4]);
            data.push(rowData[6]);
            $('#table').DataTable().row.add(data).draw(false);
          }

the problem on this is I if the issueData is empty it will just overwrite the existing data and have filter on the bottom of the datatable here's what the filter

Showing 1 to 1 of 1 entries (filtered from 3 total entries)

I don't want to filter it I just want to check if the data is existing already on a certain column then add the data if its not existing if it exist then do nothing.

Upvotes: 0

Views: 711

Answers (1)

colin0117
colin0117

Reputation: 1542

search() as you say will search the actual table. To filter it without changing the user's view of the table, use filter(). See docs here: https://datatables.net/reference/api/filter()

Upvotes: 1

Related Questions