<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    <link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
    <script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
    <link href="https://nightly.datatables.net/searchpanes/css/searchPanes.dataTables.min.css" rel="stylesheet" type="text/css" />
    <script src="https://nightly.datatables.net/searchpanes/js/dataTables.searchPanes.min.js"></script>
    <link href="https://nightly.datatables.net/select/css/select.dataTables.min.css" rel="stylesheet" type="text/css" />
    <script src="https://nightly.datatables.net/select/js/dataTables.select.min.js"></script>
    
    <meta charset=utf-8 />
    <title>DataTables - JS Bin</title>
  </head>
  <body>
    <div class="container">
      <table id="example" class="display nowrap" width="100%">
        <thead>
          <tr>
            <th>Name</th>
            <th>Position</th>
          </tr>
        </thead>
        <tfoot>
          <tr>
            <th>Name</th>
            <th>Position</th>
          </tr>
        </tfoot>
        <tbody>
          <tr>
            <td>Tiger Car Nixon</td>
            <td>System Architect</td>
          </tr>
          <tr>
            <td>Garrett House Winters</td>
            <td>Director</td>
          </tr>
          <tr>
            <td>Ashton Sea Cox</td>
            <td>Technical Author</td>
          </tr>
          <tr>
            <td>Cedric Sea Kelly</td>
            <td>Javascript Developer</td>
          </tr>
          <tr>
            <td>Jenna Car Elliott</td>
            <td>Financial Controller</td>
          </tr>
         
        </tbody>
      </table>
    </div>
  </body>
</html>
 
body {
  font: 90%/1.45em "Helvetica Neue", HelveticaNeue, Verdana, Arial, Helvetica, sans-serif;
  margin: 0;
  padding: 0;
  color: #333;
  background-color: #fff;
}
 
$(document).ready( function () {
  let searchArr = ['Car', 'House', 'Sea'];
  
  let options = [];
  searchArr.forEach(function(el) {
    options.push({
      label: el,
      value: function(rowData, rowIdx) {
        var re = new RegExp(el, 'i');
        return rowData[0].match(re);
      }
    })
  })
  
  
  
  var table = $('#example').DataTable({
    dom: 'Plfrtip',  
    columnDefs:[
        {
            searchPanes:{
              show: true,
              options: options
//                 options:[
//                     /* 1 */ {label: 'Car', value: (rowData, rowIdx) => (rowData[0].match(/car/i))},
//                     /* 2 */ {label: 'Sea', value: (rowData, rowIdx) => (rowData[0].match(/sea/i))},
//                     /* 3..169 */ 
//                     /* 170 */ {label: 'House', value: (rowData, rowIdx) => (rowData[0].match(/house/i))}
//                 ]
            },
            targets: [0]
        },
      /* //can this done with by a loop/iteration of the search array?
         //was not able to run the 
         //   columns.searchPanes.options.value()
         //inside the loop
         
       {
        searchPanes: {
          options: [
            function(){
                let retObj = {}
                searchArr.map(function (myEl) {
                    let singleObj = {
                        label: myEl,
                        value: function(rowData, rowIdx) {
                            return rowData.sub.match(/myEl/i);
                        }
                    }
                    retObj += singleObj
                })
                return retObj
            }(),
        }
      }
     */
    ]
 });
});
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers