DataTables: How to set classes to table row cells (but not to table header cells!)

前端 未结 4 1216
轻奢々
轻奢々 2021-02-05 10:36

i have a really nice style for my tables.

{ sorry links no more working }

I had to add sClass so that new rows (added by fnAddData) get the right classe

4条回答
  •  情歌与酒
    2021-02-05 10:49

      let table = $("#myTable").dataTable();
      table.rows().every(function(rowIdx, tableLoop, rowLoop){
        $(this.node().cells[0]).addClass('red');
        $(this.node().cells[1]).addClass('blue');
      }
    

    After the table is rendered, iterate through all rows with the JavaScript selector of each row and make whatever changes you want. This addresses the performance concerns brought up by gamliela in loostr's answer. DataTables rows().every() documentation

提交回复
热议问题