Sort DataTable: commit single column

I am using jQuery DataTables plugin. Sorting works fine, but is there a way to make one column invariable always, no matter what sorting is applied?

For example, the first column is just the order numbers: 1, 2, 3, 4, 5 ... And when I sort by date or something else, the first column remains in the same order: 1, 2, 3 ..?

Is there any way to do this? Thus, I am not trying to disable sorting by the first column, but make the first column the same if sorting is applied by other columns.

+4
source share
3 answers

, orderFixed, , .

, :

$('#example').dataTable( {
    "orderFixed": [ 0, 'asc' ]
} );
+1

, . , docs.

$(document).ready(function() {
var t = $('#example').DataTable( {
    "columnDefs": [ {
        "searchable": false,
        "orderable": false,
        "targets": 0
    } ],
    "order": [[ 1, 'asc' ]]
} );

t.on( 'order.dt search.dt', function () {
    t.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
        cell.innerHTML = i+1;
    } );
} ).draw();

});

order search. searchable orderable false, ( ).

0

HTML- . , .

<table class="table table-bordered" id="example" >
<thead>
<tr id="tbl_header1">
    <th  class="no-sort" name="prop_ref_no" style="min-width:80px">PropRef</th>
    <th  class="no-sort" name="title" style="min-width:80px">title</th>
    <th  name="publish_status" style="min-width:80px">Publish status</th>
    <th  name="Bedrooms" style="min-width:200px">Bedrooms</th>
</tr>
</thead>

dataTable.

$('#example').dataTable( {
    "columnDefs": [ {
      "targets": 'no-sort',
      "orderable": false,
} ]} );

SRC: https://datatables.net/forums/discussion/21164/disable-sorting-of-one-column

-1

Source: https://habr.com/ru/post/1598969/


All Articles