I am trying to have an edit button at the top of a DataTable which will pick up the value from the current selected row and append it to my url.
I have managed to get it working but not quite how I would have liked.
My Edit button which is not using the Datatable properly to get the value stored in the data table.
$.fn.dataTable.ext.buttons.edit = {
text: 'Edit',
action: function () {
var assetID;
$("#example tr.selected").each(function (index, row) {
assetID = ($(row).find("td:nth-child(2)").html());
});
if (assetID != null) {
var url = "/Demo/Edit/" + assetID;
window.location.href = url;
}
}
};
Example from Datatable site of a table with a button which shouts out the data in the current selected row. I would so much like to get my data tidier and into the datatable its self.
$(document).ready(function() {
var events = $('#events');
var table = $('#example').DataTable( {
dom: 'Bfrtip',
select: true,
buttons: [
"edit", //my edit button which works but requires external script
{ // Example button from website.
text: 'Get selected data',
action: function () {
var count = table.rows( { selected: true } ).count();
//var count = table.rows( { selected: true } ).data();
// how do i then drill down into count to get value from column 2.
events.prepend( '<div>'+count+' row(s) selected</div>' );
}
}
]
} );
} );
I have tried so many ways to try and access the object within the example from the datatables website but I just can not get the value a specific column in the selected row using their methods.
Any help would be much appreciated.