How to get selected row data?
How to get selected row data?
Alan,
I am trying to migrate from TableTools to Buttons extension.
i had created a custom button which sends the selected row table data to server and returns documents stored in database to put them in a zip file. i was using the fnGetTableData() method to retrieve the values of the selected row which is formatted as a string. and setting the sFieldSeperator attribute to set a delimiter to separate the individual column values.
$(document).ready( function () {
$('#example').DataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"aButtons": [
{
"sButtonText": "Add to Zip",
"sFieldSeperator": ";",
"bSelectedOnly": "true",
"fnClick": function ( nButton, oConfig, flash ) {
var sData = this.fnGetTableData(oConfig);
}
}
]
}
} );
} );
sData was passed as a parameter to the action class.
Is there a similar function available in Buttons extension which i can use to get the values of all the selected rows in a string format?
This question has an accepted answers - jump to answer
Answers
Create a custom button where the
action
is to usetable.rows( { selected: true } ).data();
to get the data. You can then do what you want with that data!Allan
Thanks for your reply Allan.
In the action function, the console.log shows the output as
data---[object Object]
With table tools when i was using the fnGetTableData function, the output was in string format. something like:
data---;Name;Address
;Test;1Street
;Test2;2 Street
Its basically and array of the data in the table. You can loop over it using
join();
to join the information in the rows and then a join for the outer array.This is how the export buttons do it.
Allan
Thank you so much Allan for your input!!
I ran a loop over the array to get the value for each column and then created a new array with these values and called join() method to get it in string format:
Thanks a lot for your help!