Trying to access the data in a column to pass to jquery variable

Trying to access the data in a column to pass to jquery variable

bytecbytec Posts: 37Questions: 10Answers: 0

Hi, I have a table generated by dataTables which works fine. I now need to be able to click on the table rows and return the data contained in one of the hidden columns.

Can anyone help, many thanks in advance for your help and time.

My code I am trying is

columns: [
  { data: 'RoomName',"sWidth": "15%" },   
  { data: 'ClientImage', "sWidth": "20%",  render : function (data, type){ 
    if (data != null) {
    return '<img src="' + imagepath + '' +data+'" class="WayfinderSignageImage"/>';
    } else {
    return '<img src="' + noimage + '" class="WayfinderSignageImage"/>';
    }
   }
  },
{ data: 'ClientName', "sWidth": "30%" },
{ data: 'RoomFromDate', "sWidth": "7%" },
{ data: 'RoomFromTime', "sWidth": "7%" },
{ data: 'RoomToDate',  "sWidth": "7%"},
{ data: 'RoomToTime',  "sWidth": "7%"},
{ data: 'RecordID',  render : function (data, type, full, meta) {
    var recordid = full.RecordID;
    return '<input type="button" name="edit" value="View" data-id=' + recordid + ' class="btn btn-conf-view btn-xs 
    edit_data_modal">' 
  }
  },
  ]

  $('#userTable').on( 'click', 'tr', function () {
  var id = table.row( this ).id();
  alert( 'Clicked row id '+id );
} );

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    This example here should help. If the column is invisible, the data would still be available with row().data(),

    Colin

  • bytecbytec Posts: 37Questions: 10Answers: 0

    Hi Colin, Many thanks for the pointer. All sorted.

This discussion has been closed.