jQuery datatables add class to tr

后端 未结 5 1779
孤独总比滥情好
孤独总比滥情好 2021-02-01 01:55

I am using jQuery and datatables. I want to add a class to the TR element of a particular row. I know how to find the row. The console.dir(row); shows the r

5条回答
  •  -上瘾入骨i
    2021-02-01 02:17

    To set a class name on the use this calback

    createdRow: function (row, data, dataIndex) {
        $(row).addClass('some-class-name');
    },
    

    ref: https://datatables.net/reference/option/createdRow

    To set a class on the use

    "columns": [
    { 
        data:"",
        className: "my_class",
        render: function (data, type, row) { return "..."; }
    },
    { 
        data:"",
        className: "my_class",
        render: function (data, type, row) { return "..."; }
    },
    //...
    ]
    

    Something similar for 'columnDefs'

    ref: https://datatables.net/reference/option/columns.className

    To set the Id attribute on the row use:

    //.... 
    rowId: "ShipmentId",
    columns: [...],
    //....
    

提交回复
热议问题