Get value of a column of the selected row

Get value of a column of the selected row

development@wohlsen.comdevelopment@wohlsen.com Posts: 7Questions: 2Answers: 1

I'm trying to get and use a value from the selected row. I am able to get a count of the total selected rows, but I'd like to be able to use the actual data, for instance I'd like to have javascript alert "Weekly Journal" when selecting this row. I was not able to find an example of this.

table.on( 'select', function () {
    var testValue = table.rows( { selected: true } ).count();
    alert(testValue);
} );

This question has accepted answers - jump to:

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119
    table.on( 'select', function () {
        var rowData = table.rows( { selected: true } ).data()[0];
        // now do what you need to do wht the row data
    
    } );
    
  • development@wohlsen.comdevelopment@wohlsen.com Posts: 7Questions: 2Answers: 1

    When using that line of code and doing:
    alert(rowData);

    the page alerts:
    [object Object]

    I want it to alert the value of the title column.

  • development@wohlsen.comdevelopment@wohlsen.com Posts: 7Questions: 2Answers: 1
    Answer ✓

    I got it working by adding ['title'] to the end of the line. Thanks for the help!
    var rowData = table.rows( { selected: true } ).data()[0]['title'];

  • bindridbindrid Posts: 730Questions: 0Answers: 119
    Answer ✓

    Yep. I did not include that part because it is completely dependent on your data structures. It couild be and array of arrays, or an array of object. As an array of objects your json naming conventions could be anything.

This discussion has been closed.