duanlachu7344 2019-07-18 13:56
浏览 59
已采纳

too long

My goal is every "OUT" or "IN" from database change to the red or green circle but nothing change and no error. In column IN and OUT will be contained value "IN" and value "OUT", I want to transform to green circle or red circle.

I don't know what I am doing wrong.

View

                <th scope="col">Name</th>
            <th scope="col" id="IN">IN</th>
            <th scope="col" id="OUT">OUT</th>
            <th scope="col">Comments</th>

js

    <script>
       $('table').DataTable({
   searching: false, paging: false,
    "ajax": {
        url : "<?php echo site_url("getStatu") ?>",
        type : 'GET', 
             },
        "columnDefs": [
        {
                "data" : "OUT", "orderable" : false,  "defaultContent" : "", 
            "render": function ( data, type, full, meta) {
                  if  (data=="OUT")
                  {    
                                return data ='<i class="fa fa-circle" style="font-size:36px; color:red"></i>'

                   } 
            },

        },  ]         
});

controller

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) {

           $data[] = array(
                $r->firstName,
                $r->online,
                $r->offline,
                $r->comment,

           );
      }

      $output = array(
           "draw" => $draw,
             "recordsTotal" => $status->num_rows(),
             "recordsFiltered" => $status->num_rows(),
             "data" => $data
        );
      echo json_encode($output);

}
  • 写回答

2条回答 默认 最新

  • duanping2695 2019-07-19 12:59
    关注

    try this:-

    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);
    
    }
    

    and 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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算