有没有办法使用Data table Jquery隐藏表中的列ID?

时间:2019-06-04 06:35:33

标签: jquery datatable

关于columnDefs,我有一个错误,我有datatable,其中列出了所有客户数据,但是我需要隐藏datatable的第一列,因此datatable的文档指出我要使用columnDefs。在我的本地主机中前进columnDefs很好,也很好。但是在我的作品中,columnDefs给出了错误。

Error

问题:为什么在我的作品中出现这样的错误?

我将与大家分享我的职能,其中列出了客户的所有详细信息,

<class 'str'>

HTML:

     var details = response.data;

  $.each(details, function (index, el) {

      var stringify = jQuery.parseJSON(JSON.stringify(el));
      var customer_name_each = stringify['customer_name'];
      var customer_address_each = stringify['customer_address'];
      var customer_email_each = stringify['customer_email'];
      var customer_number_each = stringify['customer_number'];
      var store_location_each = stringify['customer_location'];
      var customer_order_note_each = stringify['customer_order_note'];
      var customer_registered_each = stringify['customer_registered'];
      var customer_id_each = stringify['customer_id'];
      var customer_km = stringify['customer_km'];
      var action_each = '<center><button id="show_cart_button" class="btn btn-primary"  type="button" value='+customer_id_each+' data-toggle="modal" data-target="#add_cart" ><i class="fas fa-cart-arrow-down"></i></button></center>';

      var t = $( "#tables" ).DataTable({
        "order": [[ 0, "desc" ]],
        "bDestroy": true,
        "columnDefs": [
        {
            "targets": [ 0 ],
            "visible": false,
            "searchable": false
        }
        ]
      });
      t.row.add([
        customer_id_each,
        customer_name_each,
        customer_address_each,
        customer_email_each,
        customer_number_each,
        store_location_each,
        customer_km,
        customer_order_note_each,
        customer_registered_each,
        action_each]).draw();

    });

谢谢。

1 个答案:

答案 0 :(得分:0)

要解决问题, 这是我用来无误地隐藏列的代码,谢谢。

      var t = $( "#tables" ).DataTable({
        "order": [[ 0, "desc" ]],
        "bDestroy": true,
        // "columnDefs": [
        // {
        //     "targets": [ 0 ],
        //     "visible": false,
        //     "searchable": false
        // }
        // ]
      });
      t.column(0).visible(false);