Solved

Datatables Select All from Filtered Rows

Posted on 2016-09-22
2
147 Views
Last Modified: 2016-09-23
Hi,
I'm trying to get the items selected from the filtered rows

I've been reviewing this https://www.datatables.net/forums/discussion/comment/47085
with no luck..

The datatable buttons are set as follows

buttons: [
                    'selectAll',
                    'selectNone'
                ],
                select: true,
                select: {
                    style: 'multi',
                    selector: 'td:not(.no-clickable)'
                },

From a function I try to process the selected rows

 var myTable = $('#RequestsTable').DataTable();
       
        var data = "";
        var data = myTable.rows({ selected: true }).data();

I'm missing something here.....
0
Comment
Question by:Mauro Cazabonnet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
zephyr_hex (Megan) earned 500 total points
ID: 41811010
I would add a class to a row when it's clicked or selected, and then look for those rows when you want to process the selected rows.  Here's an example:

https://jsfiddle.net/zephyr_hex/vLx2tup3/1/

HTML
<input id="button" type="button" value="Count of Rows">
<table>
  <thead>
    <tr>
      <th>Rendering engine</th>
      <th>Browser</th>
      <th>Platform(s)</th>
      <th>Engine version</th>
      <th>CSS grade</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Trident</td>
      <td>Internet Explorer 4.0</td>
      <td>Win 95+</td>
      <td> 4</td>
      <td>X</td>
    </tr>
    <tr>
      <td>Trident</td>
      <td>Internet Explorer 5.0</td>
      <td>Win 95+</td>
      <td>5</td>
      <td>C</td>
    </tr>
    <tr>
      <td>Trident</td>
      <td>Internet Explorer 5.5</td>
      <td>Win 95+</td>
      <td>5.5</td>
      <td>A</td>
    </tr>
    <tr>
      <td>Trident</td>
      <td>Internet Explorer 6</td>
      <td>Win 98+</td>
      <td>6</td>
      <td>A</td>
    </tr>
    <tr>
      <td>Trident</td>
      <td>Internet Explorer 7</td>
      <td>Win XP SP2+</td>
      <td>7</td>
      <td>A</td>
    </tr>
  </tbody>
</table>

Open in new window


jQuery
var dt = $('table').DataTable();


$('table tbody').on('click', 'tr', function() {
  $(this).toggleClass('selected');
});

$('#button').click(function() {
  $.each(dt.rows('.selected').data(), function(key, value) {
    console.log(key);  //F12 console to see the result
    console.log(value);
  });
  alert(dt.rows('.selected').data().length + ' row(s) selected');
});

Open in new window

0
 
LVL 4

Author Closing Comment

by:Mauro Cazabonnet
ID: 41812419
Thanks for the assist

M
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
asp.net, radiobuttonlist, c# 3 69
How do I wrap text in dialog window 6 35
Ajax success not firing alert 6 43
Why is my select returning NaN 23 39
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question