Js Datatable custom Option

10/04/2020 23:26 MaLLaH95#1
Hallo,

ich habe eine Datatable und diese hat eine zusätzliche Suchfunktion via Option select.

Jetzt wollte ich aber 2 Options einfügen und irgendwie klappt es nicht so ganz

Man sollte die Tabelle nach select_tag filtern können und zusätzlich select_tag2
HTML
Code:
<div class="row">
  <div class="col-md-4 offset-md-4">
  <div class="form-control">
    <label>Filter</label>
    <select id="select_tag" class="form-control">           
    <option value="tag1">tag1</option>
    <option value="tag2">tag2</option>              
</select>
  </div>
  </div>
 
<div class="row">
  <div class="col-md-4 offset-md-4">
  <div class="form-control">
    <label>Filter</label>
    <select id="select_tag2" class="form-control">           
    <option value="de">Deutsch</option>
    <option value="en">English</option>              
</select>
  </div>
  </div>
</div>

<table id="mytable" class="table table-striped table-bordered dt-responsive" width="100%">
    <thead>
        <tr>
            <th>Column1</th>
            <th>Column2</th>
        </tr>
    </thead>
    <tbody>
        <tr data-mytag = "tag1" data-mytag2 = "de">
            <td>1</td>
            <td>German 01</td>
        </tr>
        <tr data-mytag = "tag2" data-mytag2 = "de">
            <td>2</td>
            <td>German 02</td>
        </tr>
        <tr data-mytag = "tag2" data-mytag2 = "en">
              <td>3</td>
              <td>English 01</td>
         </tr>
        <tr data-mytag = "tag1" data-mytag2 = "en">
            <td>4</td>
            <td>English 02</td>
        </tr>
    </tbody>
</table>
Javascript
Code:
var mytable= $('#mytable').DataTable();
$('#select_tag').on('change', function () {
  mytable.draw();
});

$.fn.dataTable.ext.search.push(
     function( settings, searchData, index, rowData, counter ) {
       var row = mytable.row(index).node();
       var filterValue = $(row).data('mytag');
       var e = document.getElementById("select_tag");
       var filter = e.options[e.selectedIndex].value;
       if(filterValue == filter)
          return true;
       
       return false;
 
     }
);
10/06/2020 17:52 elmarcia#2
You should stick to the api reference: [Only registered and activated users can see links. Click Here To Register...]