Skip to content

21 DataTables Change Options

M. Fares edited this page Apr 6, 2018 · 1 revision
  1. To disable sorting on the fourth column, give the targets the value 3. The first column is 0.
$('#employeesTable').dataTable( {
  "columnDefs": [
    { "orderable": false, "targets": 3 }
  ]
} );
  1. The last column is also indicated by the index -1
$('#employeesTable').dataTable( {
  "columnDefs": [
    { "orderable": false, "targets": -1 }
  ]
} );
  1. To disable ordering on multiple columns
$('#employeesTable').dataTable( {
  "columnDefs": [
    { "orderable": false, "targets": [1, 3] }
  ]
} );
  1. To enable horizontal scrolling
$('#example').dataTable( {
  "scrollX": true
} );

5 To enable vertical scrolling with pagination disabled

$('#example').dataTable( {
  "scrollY": "200px",
  "scrollCollapse": true,
  "paging": false,
  "columnDefs": [{ "orderable": false, "targets": 3 }]
} );
  1. Example: Check the view /Views/Employee/Index.cshtml

  2. References:DataTables Examples

Clone this wiki locally