2 回答
TA贡献1836条经验 获得超5个赞
尝试这个:-
public function getStatu(){
$draw = intval($this->input->get("draw"));
$start = intval($this->input->get("start"));
$length = intval($this->input->get("length"));
$this->load->model('Status_Board_Model');
$status = $this->Status_Board_Model->getStatu();
$data = array();
foreach($status->result() as $r) {
$in = $out = '';
if($r->online == 'IN'){
$in = '<i class="fa fa-circle" style="font-size:36px; color:green"></i>';
}
if($r->offline== 'OUT'){
$out = '<i class="fa fa-circle" style="font-size:36px; color:red"></i>';
}
$data[] = array(
$r->firstName,
$in,
$out,
$r->comment,
);
}
$output = array(
"draw" => $draw,
"recordsTotal" => $status->num_rows(),
"recordsFiltered" => $status->num_rows(),
"data" => $data
);
echo json_encode($output);
}
和js:-
<script>
$('table').DataTable({
searching: false, paging: false,
"ajax": {
url : "<?php echo site_url("getStatu") ?>",
type : 'GET',
},
"columnDefs": [
{
"render": function ( data, type, full, meta) {
},
}, ]
});
</script>
TA贡献1836条经验 获得超13个赞
如果请求返回正确的数据,并且INandOUT列是第 2 和第 3 列,您可以这样写:
$('table').DataTable({
searching: false, paging: false,
"ajax": {
url : "<?php echo site_url("getStatu") ?>",
type : 'GET',
},
"columnDefs": [
{
targets: 1,
data: 1,
"orderable" : false,
"defaultContent" : "",
"render": function ( data, type, full, meta) {
if (data=="IN")
{
data = '<i class="fa fa-circle" style="font-size:36px; color:green"></i>'
}
return data;
}
},
{
targets: 2,
data: 2,
"orderable" : false,
"defaultContent" : "",
"render": function ( data, type, full, meta) {
if (data=="OUT")
{
data = '<i class="fa fa-circle" style="font-size:36px; color:red"></i>'
}
return data;
}
}
]
});
- 2 回答
- 0 关注
- 140 浏览
添加回答
举报