Reputation: 1909
I'm trying to add a button in a datatable row with the following code:
$("#tbllandinfo").DataTable({
searching: false,
ordering: false,
paging: false,
bInfo: false,
ajax: {
url: '/land_and_crops/id/' + $("#eid").val(),
dataSrc: '',
},
columns: [
{ data: 'ldacres' },
{ data: 'ldyields' },
{ data: 'cname' },
{
sortable:false,
defaultContent: "<button class='btn btn-danger btn-delete form-control pull-right' dbcolid='ldid' dbcolidval= dbtable='land_det'>X</button>",
}
]
});
The button displays but the problem I'm facing is that I need to put the value of ldid
, that comes from ajax JSON into the dbcolidval attribute in the button.
Every row button will have its own value.
Sample data:
{"ldid":4,"ldentity":7,"ldacres":"5.00","ldyields":2,"ldcrop":5,"cname":"RICE"},
{"ldid":7,"ldentity":7,"ldacres":"10.00","ldyields":1,"ldcrop":6,"cname":"MAIZE",
{"ldid":6,"ldentity":7,"ldacres":"4.00","ldyields":1,"ldcrop":3,"cname":"CORN"}
Upvotes: 0
Views: 3405
Reputation: 101
Use render instead of defaultContent. See discussed here: (https://datatables.net/forums/discussion/23649/how-do-i-access-columns-data-inside-of-defaultcontent)
Upvotes: 2