Can I add an html5 data- attribute when initializing data using columns method?

Can I add an html5 data- attribute when initializing data using columns method?

puffsterpuffster Posts: 65Questions: 23Answers: 0

Sorry if this question has already been answer, I swear I've spent time looking and can't find an answer to this specific question.

I'm just wondering if there is a way to directly add an html5 data- tag directly to a column when initializing my datatable using the columns method, like below:

                columns: [
                    {
                        class: "text-left",
                        data: "destination",
                    },
                    {
                        class: "text-center",
                        data: "purpose",
                    },
                    {
                        class: "text-left",
                        data: "sponsors",
                    },
                    {
                        class: "text-left",
                        data: "chaperones",
                    },
                    {
                        class: "text-left",
                        data: "trainedStaff",
                    },
                    {
                        class: "text-center",
                        data: "transportationType",
                        ***** ADD DATA - TAG HERE *****
                        data-transBaseName = *** 
                    },
                ],

I've found this article showing how to do it using the createdRow method but wanted to see if there was a way to do it directly in the columns definition?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,838Questions: 26Answers: 5,048
    Answer ✓

    You can use columns.createdCell for that particular column.

    Kevin

  • puffsterpuffster Posts: 65Questions: 23Answers: 0
    edited March 5

    You are my new forever-hero!! :smile:

    {
        class: "text-center",
        data: "transportationType",
        createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
            $(cell).attr('data-transportName', rowData.transportationDescription);
        }
    },
    
Sign In or Register to comment.