laraveldatatablesyajra-datatable

Yajra Laravel Datatables preventing one column sorting only works when sorting another column


I'm trying to create a datatable as follows but I do not want the first and last column to be printed, sortable or even used for searches but that only works when I click on the sort buttons to sort a different column Here is my column heads

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

And here is how I am adding data to the table using datatables

       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,
            },
        ],

I expect the first and lust columns not to be sortable by default, but this only happens when I click on another column to sort it. How can I get the no sorting to work by default


Solution

  • You can try to add in columnDefs like in following code:

    columnDefs: [
        { searchable: false, targets: [0,6] },
        { orderable: false, targets: [0,6] },
        { printable: false, targets: [0,6] }
    ]