Assign variable the value of a column in a selected row

Assign variable the value of a column in a selected row

kenlistkenlist Posts: 2Questions: 0Answers: 0
edited August 2012 in General
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!

Replies

  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin
    Something a little bit like this:

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

    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.