jQuery : DataTables : Disable sorting for all columns

Enable or disable sorting of columns

Sorting of individual columns can be disabled by the “bSortable” option for each column.

Note that this will disable sorting all around, so there is no need to disable it on individual columns Continue reading

Advertisements

jQuery DataTables : Ruby On Rails : Sorting of date/time column in any format : Type based sorting

//cdn.datatables.net/plug-ins/1.10.7/sorting/datetime-moment.js

1
2
3
4
5
6
7
8
9
10
11
<script type="text/javascript" src="jquery.dataTables.js"></script>
<script type="text/javascript" src="dataTables.numericComma.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('#example').dataTable( {
            "columnDefs": [
                { "type": "numeric-comma", targets: 3 }
            ]
        } );
    } );
</script>
$.fn.dataTable.moment( '%B %e, %Y' ); // Format I used for date
$targetTable.dataTable({ /* Disable initial sort */
 "aaSorting": [],
 "order": [],
 "aoColumnDefs": [
   {
   'bSortable': false,
   'aTargets': ['action']
    }, 
   {
   "type": "datetime-moment", //use moment.js to calulate and sort date col
   targets: ['created-on', 'last-sent-on', 'date-applied']
   }
 ],
 'iDisplayLength': 10
});
<table id="bench-applicants-table">
 <thead>
 <tr>
 <th><%= t(:id) %></th>
 <th><%= t(:name) %></th>
 <th><%= t(:job_applied) %></th>
 <th><%= t(:status) %></th>
 <th><%= t(:number_of_email_sent) %></th>
 <th class="last-sent-on"><%= t(:last_sent_on) %></th>
 <th class="action"><%= t(:action) %></th>
 </tr>
 </thead>

similarly,
<th class="created-on"><%= t(:created_on) %></th>

Source: http://datatables.net/plug-ins/sorting/datetime-moment

http://datatables.net/plug-ins/sorting/

DataTables : Customizing navigation button

var $workflowTable = $('.workflow-table');
  $workflowTable.dataTable(
    {
      'iDisplayLength': 10,
      'fnDrawCallback': function (oSettings) {
        if (oSettings._iDisplayLength > oSettings.fnRecordsDisplay()) {
          $(oSettings.nTableWrapper).find('.dataTables_paginate').hide();
        }
        var curPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
        var lastPage = Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength );

        if (curPage === 1){
          $(oSettings.nTableWrapper).find('.paginate_disabled_previous').hide();
        }else{
          $(oSettings.nTableWrapper).find('.paginate_enabled_previous').show();
        }
        if(curPage === lastPage){
          $(oSettings.nTableWrapper).find('.paginate_disabled_next').hide();
        }else{
          $(oSettings.nTableWrapper).find('.paginate_enabled_next').show();
        }
      }
    }
  );