Reputation: 1136
I have several columns defined using datatables. I assign "mData" which I manipulate mRender to display. However, I would like to display two data variables in one column in order to create a link, something like this:
{"mData": "foo",
"mData2": "bar",
"mRender": function(data, data2){
return '<a href="/data/' + data + '">bar</a>'; //
}
}
Is there a way to do this?
Upvotes: 1
Views: 9154
Reputation: 21
'paging': true,
'sort': true,
'searching': true,
'scrollY':70,
"ajax": {
"url": '/Home/GetDept',
"type": "get",
"datatype" :"json"
},
"columns": [
{ "data": "city", "autoWidth": true },
{ "data": "postalcode", "autoWidth": true },
{ "data": "adress", "autoWidth": true },
{
"data": "deptid",
"data": "namedept",
"width": "50px", "render": function (data, type, row, meta) {
return '<a href="/Emp/Details?deptid=' + row.deptid + '">' + row.namedept + ' </a>';
}
}
]
})
Upvotes: 2
Reputation: 91557
The mRender
function is passed the data for the whole row. So, you can access any property you want:
{
mData: "bar",
mRender: function(data, type, val) {
switch (type) {
case 'display':
return '<a href="/data/' + data.foo + '">' + data.bar + '</a>';
break;
// optionally, add case statements for 'sort', 'filter', and 'type'
default:
return data.bar;
break;
}
}
}
Upvotes: 2