Column Reference in Another Column's HTML
Column Reference in Another Column's HTML
I'm new to DataTables but have managed to get a table up and running and now have just one issue. The table displays all the glyphs of an icon font. The first column displays the icons. The second column displays the icons' individual class names.
The JSON I am calling looks like this (the glyph that shows in the Icon column is a character in the icon font):
{
"Icon": "",
"Class": "dvi dvi-thumbs-up",
"Keywords": "Like / Thumbs Up / Approve / Agree",
"Category": "Actions1",
"Unicode": "E012"
}
In the HTML of the first column, I want to fill in the class name from the second column so the icon will display. The icon is wrapped in a button tag so it can be clicked and copied to the keyboard (using another js library):
"columns": [
{ "data": "Icon", render: function (dataField) {
return '<button class="dvi-2x ico-btn ' + ?? + '" data-clipboard-text="' + dataField + '"></button>'; }
},
{ "data": "Class" },
{ "data": "Keywords" },
{ "data": "Category" },
{ "data": "Unicode" }
The question marks are where I need to fill in some sort of reference to the Class column that contains the icon class so I can actually get the icons to display in the first column. How do I reference that column so the values will be spit into the HTML as part of the class name for each row?
This question has an accepted answers - jump to answer
Answers
There are more parameters you can use with
columns.render
. The third is contains the data for the full row. Use that parameter to get the class from the other column. See this data rendering example and column rendering example for ways to do this.Kevin
I'm not sure I understand this and I feel like this is the key part I'm missing. What parameter do I use to get the class from the other column? The examples are pretty complex and I'm not sure they doing quite the same thing I'm attempting. Thanks so much for your response and your help!
Maybe something like this:
http://live.datatables.net/hapihuva/1/edit
It uses the third parameter
row
to access the row data. Specificallyrow.Class
to access theClass
object. Is this what you are needing?Kevin
Yes! This is exactly what I was missing. Thank you, Kevin!