sorting DataTables with setting false option on ordering

余生颓废 提交于 2021-02-11 16:56:58

问题


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:


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



来源:https://stackoverflow.com/questions/60571124/sorting-datatables-with-setting-false-option-on-ordering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!