TanvirArjel TanvirArjel - 1 year ago 66
Javascript Question

How to pass one column value into another column in Jquery DataTables

I need to pass the Value of the first column into the second column render function() to make a hyperlink where the value of the first column is parameter. of the hyperlink.

"Columns": [
{
"data": "Code", "autoWidth": true,
},

{ "data" : "StyleReference","autoWidth": true,
"render": function (data, oObj) {
return '<a href="/Production/Styles/StyleDetails/' + Code + '">' + data + '</a>';
}
}
]


Any Help Please!!

Answer Source

You're nearly there. The render function can take up to 4 variables. Your row represents the whole object, this should work:

"columns": [{
  "data": "Code",
  "autoWidth": true
}, {
  "data": "StyleReference",
  "autoWidth": true,
  "render": function(data, type, row, meta) {
    return '<a href="/Production/Styles/StyleDetails/' + row.Code + '">' + data + '</a>';
  }
}]

Hope that helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download