如何在jQuery数据表中显示不同的状态背景色?

如何在jQuery数据表中显示不同的状态背景色?,jquery,datatable,Jquery,Datatable,我想在状态上显示不同的背景色,我已经显示了数据,但我不知道如何才能做到这一点,请帮助我谢谢 我想这样做,请检查 html视图 <table id="datatable" class="table table-bordered table-striped" width="100%" cellspacing="0" cellpadding="0"> <

我想在状态上显示不同的背景色,我已经显示了数据,但我不知道如何才能做到这一点,请帮助我谢谢


我想这样做,请检查

html视图

 <table id="datatable" class="table table-bordered table-striped" width="100%" cellspacing="0" cellpadding="0">
              <thead>
                <tr>
                  <th class="no-sort text-center" width="5%">S.No</th>
                   <th>Date </th>
                  <th>Member Name</th>
                  <th>End User</th>
                  <th>Status</th>

                  @if ($count > 0)
                  {{-- <th class="no-sort text-center" width="10%">Status</th> --}}
                  @endif
                </tr>
              </thead>
            </table>

您可以使用一些自定义的
CSS
状态样式,根据
状态
文本为状态的
背景
上色

列中,为
状态定义
目标4,并根据其文本(已批准、拒绝或待决)呈现
状态
,然后
返回
状态
span
td
CSS样式中

columnDefs: [{
  targets: 4,
  render: function(status, type, row, meta) {
    if (status == 'Pending') {
      status = '<td><span class="pending status">' + status + '</span></td>'
    } else if (status == 'Approved') {
      status = '<td><span class="approved status">' + status + '</span></td>'
    } else if (status == 'Reject') {
      status = '<td><span class="rejected status">' + status + '</span></td>'
    }
    return status;
  }
}]

美国号
日期
成员名称
最终用户
地位

您能否提供一个datatable的最小工作示例—JSFIDLE?我想这样做,请检查您的数据是否通过ajax加载?我相信-您希望在加载状态后立即对其进行着色?您的数据是通过ajax加载的吗?--是的,数据是由ajax加载的---是否希望在加载后立即显示状态?--是的,我想在状态上显示bg颜色,我已经显示了示例----
columnDefs: [{
  targets: 4,
  render: function(status, type, row, meta) {
    if (status == 'Pending') {
      status = '<td><span class="pending status">' + status + '</span></td>'
    } else if (status == 'Approved') {
      status = '<td><span class="approved status">' + status + '</span></td>'
    } else if (status == 'Reject') {
      status = '<td><span class="rejected status">' + status + '</span></td>'
    }
    return status;
  }
}]