How to use one column value in another column for hyperlink?
How to use one column value in another column for hyperlink?
dhDTforweb
Posts: 27Questions: 6Answers: 0
The primary key for Projects is the id.
Users need to be able to select a single project.
I want to use the project name as the link, but send the project id in the URL.
The link in the data: 'id' column works correctly.
In the code below, I need to replace
" [here I want to insert the 'id' value]"
with something like
data: 'id'
but I don't know the syntax.
Does anyone know how to work this? Thanks
var table = $('#example').DataTable( {
dom: 'Bfrtip',
ajax: {
url: '/index.php/Ajax/Projects',
type: "POST"
},
columns: [
{ data: 'id',
render: function ( data, type, row, meta ) {
return '<a href=/index.php/Project/viewSingleProject/' + data + '>'+data+'</a>';
}
},
{ data: 'projectname',
render: function ( data, type, row, meta ) {
return '<a href=/index.php/Project/viewSingleProject/ [here I want to insert the 'id' value]>'+data+'</a>';
}
},
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The
row
parameter of thecolumns.render
function contain the values for each item in the row. You would do something like this:Kevin
Thanks,
I tried this
and the value of data.id is undefined
Also tried data[0], data.0.id, etc
So where Kevin suggested "row.id", you went with "data.id"? Or am I missing something?
Sorry, I thought I tried that and it didn't work.
Just tried it again and it works perfectly.
Thanks to all!