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

前端 未结 4 1218
轻奢々
轻奢々 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条回答
  •  -上瘾入骨i
    2021-02-05 10:45

    Solution to my problem was: useing fnRowCallback instead of sClass to set classes to new rows.

      var rolesTable = $('#roles').dataTable({
          "aoColumns": [
            { "mDataProp": "id" },
            { "mDataProp": "name" },
            { "mDataProp": "module" },
            { "mDataProp": "description" },
            { "mDataProp": null, "bSearchable": false, "bSortable": false, 
              "sDefaultContent": '' }, 
          ],
          "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
              $('td:eq(0)', nRow).addClass( "avo-lime-h avo-heading-white" );
              $('td:eq(1),td:eq(2),td:eq(3)', nRow).addClass( "avo-light" );
            }
      }); // end od dataTable
    

提交回复
热议问题