toArray() pulling all info, not just selected row/s.
toArray() pulling all info, not just selected row/s.
socialinteractions
Posts: 2Questions: 1Answers: 0
Hi Guys,
I'm trying to pass the values from selected rows to an array using toArray().
I'm testing using a button with an event attached to it. If I select one row with, then click the button, it displays an array of the vales in the column for ALL records, while the count alert (correctly) shows one row selected.
Here is the jquery...
<script>
$(document).ready( function () {
var table = $('#volunteers').removeAttr('width').DataTable( {
scrollY: "800px",
scrollX: true,
select: true,
scrollCollapse: true,
columnDefs: [
{ "width": "150", "targets": 0 }
],
fixedColumns: true
} );
$('#selected').click(function () {
var array = table.rows('.selected')
.column(2)
.data()
.toArray()
alert(array);
alert( table.rows('.selected').data().length +' row(s) selected' );
});
} );
</script>
Any suggestions as to what I may be doing incorrectly?
Cheers,
J
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You will want to use
pluck()
instead ofcolumn()
. For example:Thanks kthorngren! Worked a charm.