DataTables logo DataTables

via Ad Packs
Assign variable the value of a column in a selected row
  • kenlistkenlist
    Posts: 2
    Use case:
    1. User selects a row in the table.
    2. A variable (say, acctnum) is assigned the value of the data in first column in this row.
    3. Submit button is clicked on the form and variable is passed to the server for processing.

    What would I do to have DataTables assign the value to the variable before the Submit button is pressed. How would the code look?

    Thanks in advance for your help. Still somewhat new to coding!
  • allanallan
    Posts: 15,857
    Something a little bit like this:

    table.$('tr').click( function () {
      $('input...').val( table.fnGetData( this )[0] );
    } );
    

    Note the use of fnGetData - passing in the 'TR' that was clicked on and the first index value from the data array front he object.

    There are a lot of variations on this that are possible, but this is the basic idea :-).

    Allan
This discussion has been closed.
← All Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Support

Get useful and friendly help straight from the source.

In this Discussion