如何使用codeigniter在ajax数据表中指定响应



这是我为视图文件中的数据表编写的代码(Codeigniter 3(

function trade_Datatable()
{
$.ajax({
url:'<?php echo base_url('user/get_trade_manage'); ?>',
type:'POST',
success:function(data)
{
var dataTable=$('#trade_management').DataTable({
'searching' : false,
'ordering'  : false,
'processing': true,
'serverSide': true,
'ajax':'<?php echo base_url('user/get_trade_manage'); ?>',

"rowCallback": function( row,response) {
$('td', row).css('background-color', '#00b0f0');

},
});
}
});
}
trade_Datatable();

控制器代码

......
$output['draw']=$draw;
$output['recordsTotal']=$counts;
$output['recordsFiltered']=$counts;
$output['data']=$data;
$output['colors']=$bgcolor;
echo json_encode($output);

我需要在的位置回显$bgcolor变量#00b0f0以动态应用样式。有人建议最好的答案吗?

User createdRow for apply styles in ajax datatables

$.ajax({
url:'<?php echo base_url('user/get_trade_manage'); ?>',
type:'POST',
success:function(data)
{
var dataTable=$('#trade_management').DataTable({
'searching' : false,
'ordering'  : false,
'processing': true,
'serverSide': true,
'ajax':'<?php echo base_url('user/get_trade_manage'); ?>',

columns:[
{data: 'sno'},
{data: 'created'},
{data: 'updatedon'},
{data: 'tip_type'},
{data: 'tip_for'},
{data: 'script_name'},
{data: 'tip_date'},
{data: 'tip_position'},
{data: 'tip_price'},
{data: 'action'},
{data: 'tip_exitat'},
{data: 'photo'},
{data: 'profit_loss'},  
],

createdRow: function(row, rowColors, dataIndex)
{
var colorRow = rowColors.colors;
$(row).css('background-color',colorRow);
}

});
}
});

应该在createdRow函数中传递三个参数来获取json值

var table = $('#emergency_appointment_list_test').DataTable({
"ordering": true,
"processing": true, 
"serverSide": true, 
"bDestroy": true,
"order": [], 
"language": {
"paginate": {
"previous": '<i class="fa fa-arrow-left" aria-hidden="true"></i>',
"next": '<i class="fa fa-arrow-right" aria-hidden="true"></i>'
}
},

"ajax": 
{
"url": baseurl+"emergency_app_list_test",
"type": "POST",
"data": 
{
"_token": $('#token').val(),
},


},
"columns": [
{ "data": "id" },
{ "data": "applicant_name" },
{ "data": "applicant_passport_no" },
{ "data": "serviceapplied" },
{ "data": "apptmnt_reason1" },
// { "data": "appointment_status" },
// { "data": "action" },
{ "data": "view" },
],
createdRow: function(row, rowColors, dataIndex)
{
if(rowColors.emg_status == 1)
{
$(row).css('background-color','red');
}else
{
$(row).css('background-color','');
}
}

});

相关内容

  • 没有找到相关文章

最新更新