Best way to add hidden data to cell in datatables.net?
Scenario: I am sending function_name and function_id via AJAX. The function_name is displayed in a column. When a function_name-cell is clicked, I want to to fire off a javascript with the function_id value. What is the best way to achieve this?
A thought I had was to add it to aoColumns as seen below, and make it invisible somehow. But this seems overly complicated, and it would still technically be two different cells. Is there some way to send some hidden parameter data to each cell perhap开发者_运维问答s?
Big thanks in advance
"aoColumns": [
{ "mDataProp": "function_name" }
{ "mDataProp": "function_id" }
]
I solved this by using fnGetData (http://datatables.net/ref). Apparently, the mDataProp is only for values to be displayed in the columns, and the other values are still accessible.
var oTable;
$(document).ready(function() {
oTable = $('#example').dataTable({...});
$('#example tbody tr').live('click', function () {
var data = oTable.fnGetData(this);
alert(data.function_id);
});
});
精彩评论