Column Reference in Another Column's HTML

Column Reference in Another Column's HTML

mokemonstermokemonster Posts: 10Questions: 2Answers: 0
edited May 2022 in Free community support

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

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736

    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

  • mokemonstermokemonster Posts: 10Questions: 2Answers: 0

    "The third is contains the data for the full row. Use that parameter to get the class from the other column."

    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!

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736
    Answer ✓

    Maybe something like this:
    http://live.datatables.net/hapihuva/1/edit

    It uses the third parameter row to access the row data. Specifically row.Class to access the Class object. Is this what you are needing?

    Kevin

  • mokemonstermokemonster Posts: 10Questions: 2Answers: 0

    Yes! This is exactly what I was missing. Thank you, Kevin!

Sign In or Register to comment.