How to access data

How to access data

rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0
edited December 2014 in General

Hi Allan. I was hoping you could tell me how to do this correctly... I just need to access all data within a row ID. I had a button on the table, but since I need visible variables to capture I decided to move the button to the details (using responsive plugin). Here is the buttons code that cross-posts to a separate tables New button...

//var 
// Handler for button click
    $("#Reservations tbody").on('click', 'input', function (e)
     {    //var id = $(this).parents('tr').attr('id').substring(4, 13);
      var id = $(this).parents('tr').prev().attr('id').substring(4, 13);
      var $rootRow = $(this).parents('tr').prev().find('td');
      var $detailRow = $(this).parents('ul').find('li > span.dtr-data');

      //var resDataTable = $('#Reservations').DataTable();
      //var tableData = resDataTable.data();   // or .columns.data?

      $('#ResID').val(id);
      fareedit.create({title: 'Create Fare and Assign Affiliate', buttons: 'Create and E-Mail Affiliate'});
          fareedit.field('FareID').set(id);
          fareedit.field('ResID').set(id);
          fareedit.field('FarePickupTime').set($detailRow[7].innerText);
          .......many fields.......
          fareedit.field('DriverID').set($rootRow[3].innerText);
          fareedit.field('VehicleID').set($rootRow[4].innerText);
      }                         );

I'd love to get rid of all the data-passing fields.

This question has an accepted answers - jump to answer

Answers

  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0

    Bump :( Can someone please post an example of $('#Reservations').Data() retrieving column values for the selected row? ...from within the onclick of a button I added to the row.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Hi,

    how do you get your forum [code] to work?

    It says just below the message input box :-). Also in the Markdown guide.

    Regarding your question: Use the responsive.index() method to get the row index for the selected row, then you can use row().data() to get the data for the row:

    var idx = table.responsive.index( $(this).closest('li') );
    var data = table.row( idx.row ).data();
    

    Allan

  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0

    Awesome, thanks!

This discussion has been closed.