Merge pull request #377 from DimalChandrasiri/master

Parameterized datatable sorting function
revert-70aa11f8
Kamidu Sachith Punchihewa 8 years ago committed by GitHub
commit a8e7396589

@ -29,6 +29,15 @@ $.fn.datatables_extended = function(settings){
} }
//--- End of EMM related codes //--- End of EMM related codes
/*
* Work around for accessing settings params inside datatable functions
*/
if(settings != null && settings.sorting != null && settings.sorting != undefined && settings.sorting){
elem.addClass('sorting-enabled');
}else{
elem.addClass('sorting-disabled');
}
$(elem).DataTable( $(elem).DataTable(
$.extend({},{ $.extend({},{
bSortCellsTop: true, bSortCellsTop: true,
@ -131,24 +140,41 @@ $.fn.datatables_extended = function(settings){
/** /**
* create sorting dropdown menu for list table advance operations * create sorting dropdown menu for list table advance operations
*/ */
var table = this;
if(table.hasClass('sorting-enabled')){
var dropdownmenu = $('<ul class="dropdown-menu arrow arrow-top-right dark sort-list add-margin-top-2x"><li class="dropdown-header">Sort by</li></ul>'); var dropdownmenu = $('<ul class="dropdown-menu arrow arrow-top-right dark sort-list add-margin-top-2x"><li class="dropdown-header">Sort by</li></ul>');
$('.sort-row th', elem).each(function(){ $('.sort-row th', elem).each(function () {
if(!$(this).hasClass('no-sort')){ if (!$(this).hasClass('no-sort')) {
dropdownmenu.append('<li><a href="#' + $(this).html() + '" data-column="' + $(this).index() + '">' + $(this).html() + '</a></li>'); dropdownmenu.append('<li><a href="#' + $(this).html() + '" data-column="' + $(this).index() + '">' + $(this).html() + '</a></li>');
} }
}); });
}
/** function getAdvanceToolBar(){
* append advance operations to list table toolbar if(table.hasClass('sorting-enabled')){
*/ return '<ul class="nav nav-pills navbar-right remove-margin" role="tablist">' +
$('.dataTable.list-table').closest('.dataTables_wrapper').find('.dataTablesTop .dataTables_toolbar').html('' + '<li><button data-click-event="toggle-selectable" class="btn btn-default btn-primary select-enable-btn">Select</li>' +
'<ul class="nav nav-pills navbar-right remove-margin" role="tablist">' + '<li><button data-click-event="toggle-selected" id="dt-select-all" class="btn btn-default btn-primary disabled">Select All</li>' +
'<li><button data-click-event="toggle-list-view" data-view="grid" class="btn btn-default"><i class="fw fw-grid"></i></button></li>' +
'<li><button data-click-event="toggle-list-view" data-view="list" class="btn btn-default"><i class="fw fw-list"></i></button></li>' +
'<li><button class="btn btn-default" data-toggle="dropdown"><i class="fw fw-sort"></i></button>' + dropdownmenu[0].outerHTML + '</li>' +
'</ul>'
}else{
return '<ul class="nav nav-pills navbar-right remove-margin" role="tablist">' +
'<li><button data-click-event="toggle-selectable" class="btn btn-default btn-primary select-enable-btn">Select</li>' + '<li><button data-click-event="toggle-selectable" class="btn btn-default btn-primary select-enable-btn">Select</li>' +
'<li><button data-click-event="toggle-selected" id="dt-select-all" class="btn btn-default btn-primary disabled">Select All</li>' + '<li><button data-click-event="toggle-selected" id="dt-select-all" class="btn btn-default btn-primary disabled">Select All</li>' +
'<li><button data-click-event="toggle-list-view" data-view="grid" class="btn btn-default"><i class="fw fw-grid"></i></button></li>' + '<li><button data-click-event="toggle-list-view" data-view="grid" class="btn btn-default"><i class="fw fw-grid"></i></button></li>' +
'<li><button data-click-event="toggle-list-view" data-view="list" class="btn btn-default"><i class="fw fw-list"></i></button></li>' + '<li><button data-click-event="toggle-list-view" data-view="list" class="btn btn-default"><i class="fw fw-list"></i></button></li>' +
'<li><button class="btn btn-default" data-toggle="dropdown"><i class="fw fw-sort"></i></button>'+dropdownmenu[0].outerHTML+'</li>' +
'</ul>' '</ul>'
};
}
/**
* append advance operations to list table toolbar
*/
$('.dataTable.list-table').closest('.dataTables_wrapper').find('.dataTablesTop .dataTables_toolbar').html(
getAdvanceToolBar()
); );
/** /**

@ -38,6 +38,15 @@ $.fn.datatables_extended_serverside_paging = function (settings , url, dataFilte
$(document).on('click','.viewEnabledIcon',InitiateViewOption); $(document).on('click','.viewEnabledIcon',InitiateViewOption);
} }
/*
* Work around for accessing settings params inside datatable functions
*/
if(settings != null && settings.sorting != null && settings.sorting != undefined && settings.sorting){
elem.addClass('sorting-enabled');
}else{
elem.addClass('sorting-disabled');
}
var deviceType; var deviceType;
var ownership; var ownership;

Loading…
Cancel
Save