Custom Filtering with a Button for Datatable

Im using Datatable for my current project. One of my tables has several columns. One of the columns is a column Statusthat will have one of three values Open, Rejectedand Approved. I want to filter the record shown in the table with three buttons, In Progressand Closedfor example:

<div class="btn-group pull-right">
    <button id="onprogress" class="btn btn-default filter">On Process</button>
    <button id="closed" class="btn btn-default filter">Closed</button>
    <button id="all" class="btn btn-default filter">All</button>
</div>

Here is the javascript code I used:

var dataTables = $('#datatable').DataTable({
    "info": false,
    "lengthChange": false
});

$('#all').on('click', function () {
    dataTables.columns(4).search("").draw();
});

$('#onprogress').on('click', function () {
    dataTables.columns(4).search("Open" ).draw();
}); 

$('#closed').on('click', function () {
    dataTables.columns(4).search("Rejected","Approved").draw();
});

The javascript code works well for the #onprogreess button because it only looks for one value Open. How to make it work with two-digit search?

(# closed button should show record with Rejectedor DoneStatus)

+4
2

, :

dataTable.columns(4).search("Rejected|Done", true, false, true).draw();

, :

  • :
  • Regx: (true) (default, false).
  • : ( , ) (false). .
  • CaseInsen: ( , true) (false).

+7

var table = $('# example'). DataTable();

  .columns(4)   .("")   .draw();

0

Source: https://habr.com/ru/post/1650516/


All Articles