How can I $.()serialize just the rows that are selected?

How can I $.()serialize just the rows that are selected?

Alan.HalpernAlan.Halpern Posts: 1Questions: 1Answers: 0

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

  • allanallan Posts: 63,457Questions: 1Answers: 10,465 Site admin
    Answer ✓

    99% of the way there already! Instead of using rows().data() use rows().nodes() and then use jQuery to serialise the select elements from them.

    Allan

  • DudeDude Posts: 2Questions: 0Answers: 0

    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.

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    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 know :smile:

    Kevin

  • DudeDude Posts: 2Questions: 0Answers: 0

    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.

This discussion has been closed.