Hot to access the data of the first cell for a button url paramater
Hot to access the data of the first cell for a button url paramater
I'm trying to create a button action that passes the data of the first cell as a URL variable for row (id). After updating to 1.10 the original code is failing...
ORIGINAL CODE:
fnClick: function ( button, config ) {
var data = this.fnGetSelectedData();
if ( ! data.length ) {
return;
}
window.location.assign('index.cfm?pf=1&cid=<cfoutput>#VARIABLES.cid#</cfoutput>&wid='+data[0].id);
}
NEW CODE (Failing to pass Row ID):
var table = $('#form').DataTable( {
dom: "Bfrtip",
ajax: "/report_modules/training/act/trainingtypes.php",
rowId: "id",
columns: [
{ data: "id" },
{ data: "training_type" },
{ data: "training_desc" }
],
select: true,
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor },
{
extend: "selectedSingle",
text: "View Detail"
}
]
} );
$("#form").on('click', '.buttons-selected-single', function() {
alert('Row index: ' + $(this).closest('tr').index());
});
This discussion has been closed.
Answers
You'd need to define an
actionfunction (buttons.buttons.action) for your button so it actually does something (like thefnClickyou had in TableTools).To get the selected row's data use
table.row( { selected: true } ).data(). See Select API integration.Allan
For anyone else reading this, I've just put together a little example showing how it might be done with the DataTables API: http://live.datatables.net/fapegene/1/edit .
Regards,
Allan