What is the "correct" way to get the cell information for a selected row?

What is the "correct" way to get the cell information for a selected row?

n34pandan34panda Posts: 2Questions: 1Answers: 0

Hi,

What is the correct way to get the cell information for each column from a selected row?

I have been playing with DataTables and it's going great, I am hoping now to take the cell information from a selected row and assign it to input texts on the same page as a form. Unfortunately whilst I can successfully select the row from the sample provided here: https://datatables.net/examples/api/select_single_row.html I have been unable to actually do much with the data. I have been playing with the API, specifically row(), column() and cell() with their data() method but with little success. I have also tried fn.TableTools fnGetSelectedData again with little success (always reported undefined).

Simple table initialisation:

   //initialise table
   var dataTable = $('#example').DataTable({
       searching: false,
       responsive: true
     
   });
   //hide unnecessary columns
   dataTable.columns(1).visible(false);
   dataTable.columns(2).visible(false);
   dataTable.columns(3).visible(false);
   dataTable.columns(4).visible(false);
   dataTable.columns(5).visible(false);
   dataTable.columns(6).visible(false);
   dataTable.columns(7).visible(false);
   dataTable.columns(8).visible(false);

I would appreciate any help - thanks.

Answers

  • n34pandan34panda Posts: 2Questions: 1Answers: 0
    edited April 2016

    Additional note, this is the row onclick event

     $('#example tbody').on( 'click', 'tr', function () {
    
            if ( $(this).hasClass('selected') ) {
                $(this).removeClass('selected');
            }
            else {
                dataTable.$('tr.selected').removeClass('selected');
                $(this).addClass('selected');
            }
    
        });
    

    EDIT: Really sorry didn't see the Edit Cog until now :(

  • allanallan Posts: 63,195Questions: 1Answers: 10,413 Site admin

    What is the correct way to get the cell information for each column from a selected row?

    The Select manual details how to do this.

    Allan

This discussion has been closed.