Yajra Laravel Datatables 阻止一列排序仅在对另一列进行排序时才起作用

问题描述 投票:0回答:1

我正在尝试创建一个数据表,如下所示,但我不希望打印第一列和最后一列,可排序甚至用于搜索,但这仅在我单击排序按钮对不同列进行排序时才有效 这是我的专栏标题

      <tr>
          <th><input type="checkbox" id="master"></th>
          <th>User</th>
          <th>Role</th>
          <th>Task</th>
          <th>Agent</th>
          <th>Date & Time</th>
          <th>Action</th>
      </tr>

这是我如何使用数据表将数据添加到表中

       columns: [{
                data: "id",
                render: function(data, type, row) {
                    return ('<input type="checkbox" class="sub_chk" data-id="' + data +
                        '">');

                },
                name: "Selector",
                orderable: false,
                searchable: false,
                printable: false,
            },
            {
                data: "user",
                name: "user"
            },
            {
                data: "role",
                name: "role"
            },
            {
                data: "task",
                name: "task"
            },
            {
                data: "agent",
                name: "agent"
            },
            {
                data: "created_at",
                name: "created_at"
            },
            {
                data: "id",
                render: function(data, type, row) {
                    return (
                        '<div class="row">' +
                        '<div class="col-6">' +
                        '<a href="/settings/logs/' +
                        data +
                        '/edit" class="text-dark"' +
                        'data-toggle="tooltip" data-placement="top" title="Edit">' +
                        '<i class="fa fa-pen" aria-hidden="true"></i></a>' +
                        "</div>" +
                        '<div class="col-6">' +
                        '<a rel="' +
                        data +
                        '"rel1="delete" href="javascript:"' +
                        'class="text-danger deleteLog" data-toggle="tooltip"' +
                        'data-placement="top" title="Delete"><i class="fa fa-trash"></i></a>' +
                        "</div>" +
                        "</div>"
                    );
                },
                name: "Action",
                orderable: false,
                searchable: false,
                printable: false,
            },
        ],

我希望第一列和欲望列默认情况下不可排序,但只有当我单击另一列对其进行排序时才会发生这种情况。我怎样才能让默认不排序工作

laravel datatables yajra-datatable
1个回答
0
投票

您可以尝试添加columnDefs,如以下代码所示:

columnDefs: [
    { searchable: false, targets: [0,6] },
    { orderable: false, targets: [0,6] },
    { printable: false, targets: [0,6] }
]
© www.soinside.com 2019 - 2024. All rights reserved.