简体   繁体   中英

How to make Jquery DataTable Column as HyperLink or ActionLink with other column value?

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!!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM