【问题标题】:datatables change row background colour on basis of cell column数据表根据单元格列更改行背景颜色
【发布时间】:2019-10-07 09:13:58
【问题描述】:

我在 Laravel 应用程序中有一个表格,我想根据单元格内容更改行的颜色。

我的数据表 javascript 的一部分是

ajax:"{{ route('propertiesData') }}",
          columns: [
              { data: 'address', name: 'address' },
              {data: 'town', name: 'town'},
              {data: 'postcode', name: 'postcode'},
              {data: 'units',name: 'units'},
              { data: 'examination', name: 'examination' },
              {data: 'priority', name:'priority', searchable: false},
              {data: 'completed', name:'completed'},
              {data: 'action', name: 'action', orderable: false, searchable: false},
          ],
          "createdRow": function( row, data, index ) {
                if ( data[6] == "1" )
                {
                  $(row).addClass( 'redRow' );
                }
            },

优先级字段为 1 或 0。

表格有效,但背景颜色始终为白色。

【问题讨论】:

    标签: laravel-5 datatables yajra-datatable


    【解决方案1】:

    data 很可能是一个对象,因此您必须以不同的方式访问这些值,试试这个:

    "createdRow": function (row, data, index) {
        if (data.priority === "1") {
            $(row).addClass('redRow');
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-30
      • 2020-06-02
      • 2015-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多