Can I have a link in cell but display different text?
Can I have a link in cell but display different text?
At the moment, I am doing this:
{
"targets": {{$hyperlink_column}}, // the column to add it to
"data": "hyperlink",//the field to be used for the link - report_id
"render": function ( data, type, full, meta ) {
return '<a href="/showReport?report_id='+data+'"> **link **</a>';
}
}
Ideally, I would like to display a field, instead of link, or just the data value.
I know that I could use the full and get data from another field, by referring to another column number.
Is there any way I reference a field by it's name to retrieve the data?
The reason for this, is that I use this Datatable in a reporting system, to display the results of several different queries. I therefore use it multiple times, with differing fields and numbers of columns
Thanks,
Mick
This question has an accepted answers - jump to answer
Answers
Is the "name" different from what you would find in the
full
parameter? Can you just use'+ full.myFieldName +'
or similar?Allan
The columns.render documentation shows various ways to use the function.
You will need to use "data.fieldname" to refer to a specific item in the row.
https://datatables.net/reference/option/columns.render
full
looks like thisShould that have the field names in?
Looking at your example, you have:
Hmmmm, why don't I have the field names....
debug code: iqerip
One of my other Datatables gives this for
full
:but I can't see what is different.
It will depend totally on how you are populating the DataTable. The
full
parameter is giving you the original data object for the table - that might be an array or an object. It depends how you initialise the table. This section of the manual explains more about the underlying data.Allan
In this case, I create a HTML table, then just do this:
Got the names in the row by doing this:
[https://datatables.net/examples/advanced_init/object_dom_read.html]
If your table data is being read from HTML and you don't use
columns.data
, it will be read into an array - one element for each column.Allan