diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/data-tables-extended.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/data-tables-extended.hbs index ebe533ca136..0bb33aa8cb8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/data-tables-extended.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/data-tables-extended.hbs @@ -19,9 +19,10 @@ {{~css "css/dataTables.bootstrap.css"}} {{~css "css/dataTables.responsive.css"}} {{/zone}} -{{~#zone "bottomJs"}} +{{#zone "bottomJs"}} {{~js "js/jquery.dataTables.min.js"}} {{~js "js/dataTables.bootstrap.js"}} {{~js "js/dataTables.responsive.min.js"}} {{~js "js/dataTables.extended.js"}} + {{~js "js/dataTables.extended.serversidepaging.js"}} {{/zone}} 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 new file mode 100644 index 00000000000..1ac4db312d2 --- /dev/null +++ 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 @@ -0,0 +1,281 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * ========================================================= + * data-tables extended function (Server-side Pagination) + * ========================================================= + */ + +/** + * @namespace $ + * The $ is just a function. + * It is actually an alias for the function called jQuery. + * For ex: $(this) means jQuery(this) and S.fn.x means jQuery.fn.x + */ + + $.fn.datatables_extended_serverside_paging = function (settings , url, dataFilter, + columns, fnCreatedRow, fnDrawCallback) { + var elem = $(this); + + // EMM related function + if (initiateViewOption) { + $(".viewEnabledIcon").bind("click", initiateViewOption); + } + //--- End of EMM related codes + + $(elem).DataTable( + $.extend({},{ + serverSide: true, + bSortCellsTop: true, + ajax : { + url: "/emm/api/data-tables/invoker", + data : function (params) { + var filter = ""; + var i; + for (i = 0; i < params.columns.length; i++) { + // console.log(i); + filter += "&" + params.columns[i].data + "=" + params.columns[i].search.value; + } + // console.log(filter); + params.offset = params.start; + params.limit = params.length; + params.filter = filter; + params.url = url; + }, + dataFilter: dataFilter + }, + columns: columns, + responsive: false, + autoWidth: false, + dom:'<"dataTablesTop"' + + 'f' + + '<"dataTables_toolbar">' + + '>' + + 'rt' + + '<"dataTablesBottom"' + + 'lip' + + '>', + language: { + searchPlaceholder: 'Search by Role name', + search: '' + }, + fnCreatedRow: fnCreatedRow, + "fnDrawCallback": fnDrawCallback, + initComplete: function () { + this.api().columns().every(function () { + + var column = this; + var filterColumn = $('.filter-row th', elem); + + /** + * Create & add select/text filters to each column + */ + if (filterColumn.eq(column.index()).hasClass('select-filter')) { + var select = $('') + .appendTo(filterColumn.eq(column.index()).empty()) + .on('change', function () { + var val = $.fn.dataTable.util.escapeRegex( + $(this).val() + ); + + column + //.search(val ? '^' + val + '$' : '', true, false) + .search(val ? val : '', true, false) + .draw(); + + if (filterColumn.eq(column.index()).hasClass('data-platform')) { + if (val == null || val == undefined || val == "") { + $("#operation-bar").hide(); + $("#operation-guide").show(); + } else { + $("#operation-guide").hide(); + $("#operation-bar").show(); + loadOperationBar(val); + } + } + }); + + $(column).each(function () { + if ($(column.nodes()).attr('data-search')) { + var titles = []; + column.nodes().unique().sort().each(function (d, j) { + var title = $(d).attr('data-display'); + if ($.inArray(title, titles) < 0) { + titles.push(title); + if (title !== undefined) { + select.append('') + } + } + }); + } else { + column.data().unique().sort().each(function (d, j) { + select.append('') + }); + } + }); + } else if (filterColumn.eq(column.index()).hasClass('text-filter')) { + var title = filterColumn.eq(column.index()).attr('data-for'); + $(filterColumn.eq(column.index()).empty()).html(''); + + filterColumn.eq(column.index()).find('input').on('keyup change', function () { + column.search($(this).val()).draw(); + if ($('.dataTables_empty').length > 0) { + $('.bulk-action-row').addClass("hidden"); + } else { + $('.bulk-action-row').removeClass("hidden"); + } + }); + } + + }); + + /** + * search input default styles override + */ + var search_input = $(this).closest('.dataTables_wrapper').find('div[id$=_filter] input'); + search_input.before('').removeClass('input-sm'); + + /** + * create sorting dropdown menu for list table advance operations + */ + var dropdownmenu = $('
'); + $('.sort-row th', elem).each(function () { + if (!$(this).hasClass('no-sort')) { + dropdownmenu.append('