From 3e4c1f912113522a31fca215c5b60c4632aea40f Mon Sep 17 00:00:00 2001 From: Imesh Chandrasiri Date: Fri, 7 Oct 2016 10:11:21 +0530 Subject: [PATCH] Parametarized datatable sorting function --- .../public/js/dataTables.extended.js | 54 ++++++++++++++----- .../dataTables.extended.serversidepaging.js | 9 ++++ 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js index 812acca6f7..5de71a61d8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.js @@ -30,6 +30,15 @@ $.fn.datatables_extended = function(settings){ } //--- 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( $.extend({},{ bSortCellsTop: true, @@ -132,24 +141,41 @@ $.fn.datatables_extended = function(settings){ /** * create sorting dropdown menu for list table advance operations */ - var dropdownmenu = $(''); - $('.sort-row th', elem).each(function(){ - if(!$(this).hasClass('no-sort')){ - dropdownmenu.append('
  • ' + $(this).html() + '
  • '); - } - }); + var table = this; + if(table.hasClass('sorting-enabled')){ + var dropdownmenu = $(''); + $('.sort-row th', elem).each(function () { + if (!$(this).hasClass('no-sort')) { + dropdownmenu.append('
  • ' + $(this).html() + '
  • '); + } + }); + } + + function getAdvanceToolBar(){ + if(table.hasClass('sorting-enabled')){ + return '' + }else{ + return '' + }; + } + /** * append advance operations to list table toolbar */ - $('.dataTable.list-table').closest('.dataTables_wrapper').find('.dataTablesTop .dataTables_toolbar').html('' + - '' + $('.dataTable.list-table').closest('.dataTables_wrapper').find('.dataTablesTop .dataTables_toolbar').html( + getAdvanceToolBar() ); /** diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js index 3dc7ce83d0..ddd2350055 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js @@ -38,6 +38,15 @@ $.fn.datatables_extended_serverside_paging = function (settings , url, dataFilte $(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 ownership;