最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery DataTables: display rows in the original data source order, while keeping sorting feature available - Stack

programmeradmin1浏览0评论

I wish to display a list of items in the order in which they are returned from my data source initially but still give the user the ability to sort on columns if they so wish.

In order to do this, i set the order attribute to false like so:

$('#table_id').DataTable({
    order: false;
 });

What this does however is hide the up/down caret symbols effectively disabling sorting. It seems that they only appear if you set order to an array of arrays (like [[1, "asc"]] for example).

I have looked into the bSort attribute but that doesnt seem to work..

Any ideas on how i can display a list in the order in which it es first?

Note: the datasource is a web service which returns a block of html that has the desired order of elements.

I wish to display a list of items in the order in which they are returned from my data source initially but still give the user the ability to sort on columns if they so wish.

In order to do this, i set the order attribute to false like so:

$('#table_id').DataTable({
    order: false;
 });

What this does however is hide the up/down caret symbols effectively disabling sorting. It seems that they only appear if you set order to an array of arrays (like [[1, "asc"]] for example).

I have looked into the bSort attribute but that doesnt seem to work..

Any ideas on how i can display a list in the order in which it es first?

Note: the datasource is a web service which returns a block of html that has the desired order of elements.

Share Improve this question edited Mar 7, 2019 at 8:38 user3307073 asked Mar 7, 2019 at 3:58 NotarasNotaras 7372 gold badges18 silver badges52 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

You need to set order option, which defines initial sorting order (in form of array), to empty array, so that it will keep your data entries in their original order, while letting the users to sort the table afterwards:

$('#table_id').DataTable({
    order: [];
});

For older version use this

$(document).ready( function() {
    $('#example').dataTable({
        /* Disable initial sort */
        "aaSorting": []
    });
})

newer versions

$(document).ready( function() {
    $('#example').dataTable({
        /* No ordering applied by DataTables during initialisation */
        "order": []
    });
})

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论