如何在内部数据表中验证状态列?

时间:2016-12-21 03:49:25

标签: jquery codeigniter datatables

我想验证状态== 1然后显示活动范围,如果不显示非活动状态,但我怎么能用数据表做这个我尝试使用jquery ajax没有数据表status = (Data[i][5] == 1) ? "<span class='label label-success'>active</span>":"<span class='label label-danger'>inactive</span>";

控制器

public function datatable(){
        $array = $this->products->datatable();
        $this->json($array);
        $data = array();
        foreach ($array as $rows){
            array_push($data, array(
                $rows['id'],
                $rows['descripcion'],
                $rows['precio_compra'],
                $rows['precio_venta'],
                $rows['precio_mayoreo'],    
                $rows['existencia'],
                $rows['status']
            ));
        }
        $this->json(array('data' => $data));
    }

AJAX

var table = $('#example').DataTable({
        "lengthChange": false,
        ajax: {
            url: URL_GET_DATATABLE,
            type: 'POST',
        },
        columnDefs:[{
            targets: -1,
            data: null,
            defaultContent: "<button>Click!</button>"
        }],
    });

如何验证跨度文本的更改?

datatable

1 个答案:

答案 0 :(得分:1)

尝试这样的事情(未经测试)。

var table = $('#example').DataTable({
    "lengthChange": false,
    ajax: {
        url: URL_GET_DATATABLE,
        type: 'POST',
    },
    columnDefs:[{
        targets: -1,
        data: null,
        defaultContent: "<button>Click!</button>"
        },
        { 
        targets: 6,
        render : function(data, type, row) {
                return '<span class="label label-' + (data[6] == 1 ? 'success' : 'danger') + '">' + (data[6] == 1 ? 'active' : 'inactive') + '</span>'
            }
        }
    ]
});

修改:这是working fiddle