How can I $.()serialize just the rows that are selected?
How can I $.()serialize just the rows that are selected?
Hello guys, I am using DataTables and I am having some troubles with get the data from the all the rows that are selected, I am using a check box on my table, all the rows have a little form using a dropdown select as a input, with some pre-established options depending of the row, I already put the dropdown list as cell, like the exemple of form on dataTable.
How can I get the data just from the select row, with the form already $.()serialized ??
I have tried this code
$(document).ready( function () {
var table = $('#myTable').DataTable(
'buttons' : [ {
extend: 'selected',
text: 'Count selected rows',
action: function ( e, dt, button, config,indexes ) {
var rowData = table.rows( { selected: true }).data().toArray().$('select').serialize();
alert(JSON.stringify(rowData))
} }]
);
// ...
});
This question has an accepted answers - jump to answer
Answers
99% of the way there already! Instead of using
rows().data()
userows().nodes()
and then use jQuery to serialise theselect
elements from them.Allan
Hi Allan,
Can you please help me how to build the jQuery to serialise in this example
I am trying to use var rowData = table.rows( { selected: true }).nodes().$('select').serialize();
but it is not working.
You probably need to add
toArray()
to serialize just data. Otherwise you are trying to serialize the API objects which isn't going to work. Ask me how I knowKevin
Hi Kevin,
My datatable has one input column and multi-select checkboxes. I am trying to serialize only the input field data for the rows which are selected.
var table = $('#table-example').DataTable();
var params = table.$('input').serializeArray();
params is listing for all rows. I need only the selected rows input values.