Есть ли способ скрыть идентификатор столбца в таблице с помощью таблицы данных Jquery? - PullRequest
0 голосов
/ 04 июня 2019

У меня есть ошибка, связанная с columnDefs, у меня есть таблица данных, где я перечисляю все данные о клиентах, однако мне нужно скрыть первый столбец таблицы данных, поэтому документы datatable указывают мне на использование columnDefs. двигаться вперед в моем локальном хосте columnDefs хорошо работают и хорошо. однако в моем производстве columnDefs выдает ошибку.

Error

Вопрос: почему в моем производстве выдается такая ошибка?

Я поделюсь с вами, ребята, моей функцией, где я перечислю все детали клиентов,

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

    });

Html

    <table id="tables" class="table table-striped" style="width:100%;">
        <thead>
            <tr style="font-size:14px;">
                <th scope="col">ID</th>
                <th scope="col">Name</th>
                <th scope="col">Ship to</th>
                <th scope="col">Email</th>
                <th scope="col">Telephone</th>
                <th scope="col">Store Location</th>
                <th>Destination Kilometers</th>
                <th scope="col">Customer Other Details</th>
                <th scope="col">Date Called</th>
                <th scope="col">Action</th>
            </tr>
        </thead>
        <tbody style=" font-size:14px;">

        </tbody>
    </table>

Заранее спасибо.

1 Ответ

0 голосов
/ 04 июня 2019

Чтобы решить проблему, это код, который я использовал, чтобы скрыть столбец без ошибок, спасибо.

      var t = $( "#tables" ).DataTable({
        "order": [[ 0, "desc" ]],
        "bDestroy": true,
        // "columnDefs": [
        // {
        //     "targets": [ 0 ],
        //     "visible": false,
        //     "searchable": false
        // }
        // ]
      });
      t.column(0).visible(false);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...