Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery DataTables - Serialize is not working

I'm using jQuery DataTables.

This is my markup:

<div class='wrapper'>
    <form>
         <table>
              <tr>
                    <td><input type='checkbox' value='1' /></td>
                    <td>Some Data</td>
              </tr>
         </table>
    </form>
</div>
<button>delete</button>

I have multiple rows and each has a checkbox. Normally, I would do this to grab all inputs inside the form:

var data = $('form input').serialize();

But, since I'm using DataTables, it says here I should use this instead:

var oTable = $('table').dataTable();
var data = $('input', oTable.fnGetNodes()).serialize();

Unfortunately, console.log(data) here returns (empty string). I've been reading up on documentation but, so far, nothing has helped.

I tried logging oTable.fnGetNodes() and it returns the tr's of the table. I'm at a loss here. Any help is appreciated.

like image 487
rgin Avatar asked Mar 05 '26 10:03

rgin


1 Answers

<td><input type='checkbox' value='1' /></td>

You need the name attribute for serialize to work here. Otherwise, it doesn't see any valid form elements inside the form.

<td><input type='checkbox' value='1' name='check[]' /></td>
like image 166
rgin Avatar answered Mar 07 '26 00:03

rgin