datatable select all lines containing a searched item

datatable select all lines containing a searched item

messaoudmessaoud Posts: 4Questions: 3Answers: 0

Hi everyone, I am new to javaScript
The objective is to color or select all the rows of the table (dataTable) which includes for example the name of a city "new york" in a button
I have already tried with the 'rowCallback' however it does the action just on the first page and as soon as you go to the second you have to click again.
how could I modify the code below in order to solve the problem?:

       $(document).ready(function() {
         var table = $("#myTable").DataTable({
         // Select all rows that match a specific dept
          function selectdepts(table, office) {
             var oTable = $('#' + table).DataTable();
              var oTT = TableTools.fnGetInstance(table);
              // deselect everything.
              oTable.rows().indexes().each(
                  function(idx) {
                      oTT.fnDeselect(oTable.rows(idx).nodes().to$());
                  }
              );
              oTable.rows().indexes().each(
                  function(idx) {
                      if (oTable.row(idx).data().office === office) { // get Value of button ??
                          oTT.fnSelect(oTable.rows(idx).nodes().to$());
                      }
                  }
              );
              //var s = oTT.fnGetSelected();
              //console.log( "fngetselected length: " + s.length );
          }

      });
  });



          <div>
             <button id="s1">TOKYO</button>
             <button id="s2">SAN FRANCISCO</button>
           </div>
Name Position Office Age Start date Salary
Tiger Nixon System Architect Edinburgh 61 2011/04/25 $320,800
Garrett Winters Accountant Tokyo 63 2011/07/25 $170,750
Ashton Cox Junior Technical Author San Francisco 66 2009/01/12 $86,000
Cedric Kelly Senior Javascript Developer Edinburgh 22 2012/03/29 $433,060
Airi Satou Accountant Tokyo 33 2008/11/28 $162,700
Brielle Williamson Integration Specialist New York 61 2012/12/02 $372,000
Herrod Chandler Sales Assistant San Francisco 59 2012/08/06 $137,500
Rhona Davidson Integration Specialist Tokyo 55 2010/10/14 $327,900
Colleen Hurst Javascript Developer San Francisco 39 2009/09/15 $205,500
Sonya Frost Software Engineer Edinburgh 23 2008/12/13 $103,600
Name Position Office Age Start date Salary

Answers

  • colincolin Posts: 15,114Questions: 1Answers: 2,583

    As we said in your other thread, rowCallback would be the way to go. It's called every time a row is drawn, so it would be called on all other pages.

    If you need more help with this, please provide a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

Sign In or Register to comment.