0

Is it possible setting default sorting table by second column with disable change sorting?

I try in this way but on header of second column an arrow is visible. I want remove all arrow with the default sorting.

var table = data.DataTable({
    "pageLength": 5,
    "lengthChange": false,
    "info" : false,
    "responsive": true,
    "ordering": true,
    "order": [ 1, "asc" ],
    "columnDefs": [{
    "targets": "_all", "orderable": false
    }],
    "data": result,
    "columns": [
        { "data": null },
        { "data": "Class" },
        { "data": "count" },
        { "data": "group" }
        ]
});

table.on('order.dt', function () {
    table.column(0, { search: 'applied', order: 'applied' }).nodes()
    .each(function (cell, i) {
          cell.innerHTML = i + 1;
    });
}).draw();
1
  • Could you please provide more of your code. Kinda hard to know where this code fits in without having good knowledge and fresh experience with Jquery DataTables. That way you will reach more developers willing to take a look. Commented Mar 6, 2020 at 22:31

1 Answer 1

1

You can use this jQuery command to remove the grey triangle (background image) from the element:

$("th.sorting_desc").css('background-image', 'none');

This needs to be placed at the end of the "document ready" section (assuming that is what you are doing).

The only thing I would add is this: The triangle is there for a reason - to tell users how the data is sorted. I'd be reluctant to remove it myself (just my opinion).

(Your "targets": "_all", "orderable": false has taken care of the sorting question already. The table is not sortable by the user, once it has been displayed.)

Update

You may also want to stop the cursor from changing, when you roll over the table heading (for consistency of UI experience):

$("th.sorting_desc").css('cursor', 'default');

(Tested only in Firefox and Chrome.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.