put 'input' in every cell and get their content, **including other pages**

put 'input' in every cell and get their content, **including other pages**

trucmuche2005trucmuche2005 Posts: 71Questions: 22Answers: 2
edited April 2022 in Free community support

Hello,

I have a DataTables with 20 pages and, using 'render' function, I can add an input box into each cell of a given column. That's ok. In 'column' part of DataTables initialization, I have the following :

{name: 'colname', data: null, 
render:function ( data, type, row ) { 
return "<input type='text' class='form-control' value='' name='inputname'>";
}
},

Now, imagine that the user puts some text into those input on different pages, and I would like to grab all input values when the user clicks on a button. In the 'on('click' ...' event catcher, I have that :

$( "input[name='inputname']" ).each(function( index, element ) {
        console.log( index, element );
});

The problem is that it only gets the displayed elements but it does not log ALL the elements in the DataTables, including those which are displayed on a different page...

How can I extract ALL the values of the 'inputname' input elements ??

Thanks,

T.

Answers

  • kthorngrenkthorngren Posts: 20,386Questions: 26Answers: 4,783

    I think you can do something like this:

    table.rows().nodes().to$().find( "input[name='inputname']" ).each(function( index, element ) {
            console.log( index, element );
    });
    

    Where table is an instance of the Datatables API. It uses rows().nodes() and. -to$()` to allow jQuery find() to be used.

    Kevin

  • trucmuche2005trucmuche2005 Posts: 71Questions: 22Answers: 2

    YES ! Thank you very much ! That's perfect :-)

Sign In or Register to comment.