Reputation: 9055
How to get from mData property a given cells value? I have the following code with the table initialization, I add dynamically cell values to my table specific column and I would like to define the data-id using the value of clicked rows hidden cell. If I alert (source
) I can see the comma separated data string. I would like to hole up the first value.
/* Table initialisation */
$(document).ready(function() {
var oTable = $('#example').dataTable( {
"aoColumnDefs": [ {
"aTargets": [ 15 ],
"mData": function ( source, type, val ) {
alert(source);
return "<a id='MyModal' data-id='" + source.my-id + "' href='#'>Edit</a> | <a href ='action.php?id='>Delete</a>";
}
} ]
} );
} );
Upvotes: 0
Views: 5639
Reputation: 511
Yes. Instead of using mData, you should used mRender.
The difference between mData and mRender is that you're not supposed to used both of them at same time. If you want to manipulate the model & based on condition you are going to render the page then used mRender, but in mData you are directly binding the model in columns.
Upvotes: 1
Reputation: 37061
If I got you right , val[0]
, val[1]
etc... is the thing you are looking for
Also , I think you should replace mData
replace with mRender
"mRender": function ( source, type, val ) {
alert(source);
return "<a id='MyModal' data-id='" + source.my-id + "' href='#'>Edit</a> | <a href ='action.php?id='>Delete</a>";
}
Upvotes: 1