From 5a9cd2ac6dd4a91c30ef721e0927354e24d61f49 Mon Sep 17 00:00:00 2001 From: Shalimov Date: Fri, 9 Jun 2017 14:01:13 +0300 Subject: [PATCH 1/6] Update pagination helpers --- .../mdtAjaxPaginationHelperFactory.js | 4 + .../factories/mdtPaginationHelperFactory.js | 11 +- .../main/templates/rows/generateRows.html | 2 +- dist/md-data-table-templates.js | 42 +-- dist/md-data-table.js | 303 +++++++++--------- 5 files changed, 190 insertions(+), 172 deletions(-) diff --git a/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js b/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js index 1bd3a92..abc0732 100644 --- a/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js +++ b/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js @@ -58,6 +58,10 @@ return this.totalResultCount; }; + mdtPaginationHelper.prototype.trackBy = function(item, $index) { + return item[(this.rowOptions && this.rowOptions.trackKey)] || $index; + }; + mdtAjaxPaginationHelper.prototype.getRows = function(){ return this.dataStorage.storage; }; diff --git a/app/modules/main/factories/mdtPaginationHelperFactory.js b/app/modules/main/factories/mdtPaginationHelperFactory.js index dfc0d6a..bf4e238 100644 --- a/app/modules/main/factories/mdtPaginationHelperFactory.js +++ b/app/modules/main/factories/mdtPaginationHelperFactory.js @@ -3,8 +3,9 @@ function mdtPaginationHelperFactory(PaginatorTypeProvider, _){ - function mdtPaginationHelper(dataStorage, paginationSetting){ + function mdtPaginationHelper(dataStorage, paginationSetting, rowOptions){ this.paginatorType = PaginatorTypeProvider.ARRAY; + this.rowOptions = rowOptions; this.dataStorage = dataStorage; @@ -51,6 +52,10 @@ return this.dataStorage.storage.length; }; + mdtPaginationHelper.prototype.trackBy = function(item, $index) { + return item[(this.rowOptions && this.rowOptions.trackKey)] || $index; + }; + mdtPaginationHelper.prototype.getRows = function(){ this.calculateVisibleRows(); @@ -85,8 +90,8 @@ }; return { - getInstance: function(dataStorage, isEnabled){ - return new mdtPaginationHelper(dataStorage, isEnabled); + getInstance: function(dataStorage, isEnabled, rowOptions){ + return new mdtPaginationHelper(dataStorage, isEnabled, rowOptions); } }; } diff --git a/app/modules/main/templates/rows/generateRows.html b/app/modules/main/templates/rows/generateRows.html index f194732..eb1b279 100644 --- a/app/modules/main/templates/rows/generateRows.html +++ b/app/modules/main/templates/rows/generateRows.html @@ -1,5 +1,5 @@ diff --git a/dist/md-data-table-templates.js b/dist/md-data-table-templates.js index 213a0f7..2778467 100644 --- a/dist/md-data-table-templates.js +++ b/dist/md-data-table-templates.js @@ -1,21 +1,21 @@ -angular.module("mdtTemplates", []).run(["$templateCache", function($templateCache) {$templateCache.put("/main/templates/generateTable.html","\r\n \r\n \r\n \r\n
\r\n
\r\n\r\n\r\n \r\n \r\n
\r\n"); -$templateCache.put("/main/templates/largeEditDialog.html","\r\n \r\n
\r\n

{{cellData.attributes.editableFieldTitle}}

\r\n \r\n\r\n \r\n \r\n \r\n
\r\n
\r\n\r\n \r\n {{mdtTranslations.largeEditDialog.saveButtonLabel}}\r\n {{mdtTranslations.largeEditDialog.cancelButtonLabel}}\r\n \r\n
\r\n"); -$templateCache.put("/main/templates/mdtAlternateHeaders.html","
\r\n {{getNumberOfSelectedRows()}} item selected\r\n \r\n \r\n \r\n\r\n \r\n \r\n \r\n
"); -$templateCache.put("/main/templates/mdtCardFooter.html","
\r\n
\r\n\r\n {{mdtTranslations.rowsPerPage}}\r\n \r\n \r\n {{pageSize}}\r\n \r\n \r\n\r\n \r\n {{mdtPaginationHelper.getStartRowIndex()+1}}-{{mdtPaginationHelper.getEndRowIndex()+1}} of {{mdtPaginationHelper.getTotalRowsCount()}}\r\n \r\n\r\n \r\n \r\n \r\n\r\n \r\n \r\n \r\n
\r\n
"); -$templateCache.put("/main/templates/mdtCardHeader.html","
\r\n {{tableCard.title}}\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n \r\n
"); -$templateCache.put("/main/templates/mdtCheckboxColumnFilter.html","
\r\n
\r\n \r\n
\r\n Sort A-Z \r\n
\r\n\r\n
\r\n Select all - Clear\r\n\r\n
{{selectedItems.length}} Selected
\r\n
\r\n\r\n
\r\n \r\n {{ transformChip(item) }}\r\n \r\n
\r\n\r\n
\r\n Ok\r\n Cancel\r\n
\r\n
\r\n
\r\n
\r\n"); -$templateCache.put("/main/templates/mdtChipsColumnFilter.html","
\r\n
\r\n \r\n
\r\n Sort A-Z \r\n
\r\n\r\n
\r\n \r\n\r\n \r\n\r\n {{transformChip(item)}}\r\n\r\n \r\n No results found.\r\n \r\n \r\n\r\n \r\n \r\n {{transformChip($chip)}}\r\n \r\n \r\n\r\n \r\n
\r\n\r\n
\r\n Ok\r\n Cancel\r\n
\r\n
\r\n
\r\n
\r\n"); -$templateCache.put("/main/templates/mdtColumnSelector.html","\r\n
\r\n
\r\n \r\n
\r\n Columns\r\n
\r\n
\r\n Select all - Clear\r\n\r\n
{{selectedItems.length}} Selected
\r\n
\r\n\r\n
\r\n \r\n {{item.columnName}}\r\n \r\n
\r\n\r\n
\r\n Ok\r\n Cancel\r\n
\r\n
\r\n
\r\n
\r\n"); -$templateCache.put("/main/templates/mdtDropdownColumnFilter.html","
\r\n
\r\n \r\n
\r\n Sort A-Z \r\n
\r\n\r\n
\r\n \r\n \r\n \r\n {{transformChip(item)}}\r\n \r\n \r\n \r\n
\r\n\r\n
\r\n Ok\r\n Cancel\r\n
\r\n
\r\n
\r\n
\r\n"); -$templateCache.put("/main/templates/mdtGeneratedHeaderCellContent.html","
\r\n \r\n \r\n\r\n \r\n \r\n\r\n\r\n \r\n \r\n\r\n
\r\n {{headerRowData.columnDefinition}}\r\n\r\n \r\n\r\n \r\n\r\n \r\n
\r\n
\r\n {{headerRowData.columnDefinition}}\r\n\r\n \r\n
\r\n
"); -$templateCache.put("/main/templates/mdtGeneratedHeaderRow.html","\r\n\r\n \r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n \r\n\r\n"); -$templateCache.put("/main/templates/mdtTable.html","\r\n \r\n \r\n\r\n \r\n \r\n \r\n\r\n \r\n \r\n
\r\n\r\n \r\n\r\n \r\n
\r\n\r\n \r\n \r\n \r\n
\r\n\r\n"); -$templateCache.put("/main/templates/smallEditDialog.html","\r\n \r\n
\r\n \r\n\r\n \r\n \r\n \r\n
\r\n
\r\n
\r\n"); -$templateCache.put("/main/templates/cells/generateCell.html","\r\n\r\n\r\n\r\n\r\n\r\n\r\n"); -$templateCache.put("/main/templates/cells/generateCellValue.html","\r\n {{headerRowData.columnName}}\r\n\r\n\r\n\r\n {{headerRowData.columnName}}\r\n \r\n"); -$templateCache.put("/main/templates/cells/generateCheckboxCell.html","\r\n"); -$templateCache.put("/main/templates/cells/generateSortingIcons.html","\r\n \r\n\r\n\r\n\r\n \r\n"); -$templateCache.put("/main/templates/rows/errorIndicator.html","\r\n \r\n\r\n"); -$templateCache.put("/main/templates/rows/generateRows.html","\r\n\r\n \r\n\r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n"); -$templateCache.put("/main/templates/rows/generateRowsVirtualRepeat.html","\r\n\r\n \r\n\r\n \r\n\r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n"); -$templateCache.put("/main/templates/rows/noResultIndicator.html","\r\n \r\n\r\n");}]); \ No newline at end of file +angular.module("mdtTemplates", []).run(["$templateCache", function($templateCache) {$templateCache.put("/main/templates/generateTable.html","\n \n \n \n
\n
\n\n\n \n \n
\n"); +$templateCache.put("/main/templates/largeEditDialog.html","\n \n
\n

{{cellData.attributes.editableFieldTitle}}

\n \n\n \n \n \n
\n
\n\n \n {{mdtTranslations.largeEditDialog.saveButtonLabel}}\n {{mdtTranslations.largeEditDialog.cancelButtonLabel}}\n \n
\n"); +$templateCache.put("/main/templates/mdtAlternateHeaders.html","
\n {{getNumberOfSelectedRows()}} item selected\n \n \n \n\n \n \n \n
"); +$templateCache.put("/main/templates/mdtCardFooter.html","
\n
\n\n {{mdtTranslations.rowsPerPage}}\n \n \n {{pageSize}}\n \n \n\n \n {{mdtPaginationHelper.getStartRowIndex()+1}}-{{mdtPaginationHelper.getEndRowIndex()+1}} of {{mdtPaginationHelper.getTotalRowsCount()}}\n \n\n \n \n \n\n \n \n \n
\n
"); +$templateCache.put("/main/templates/mdtCardHeader.html","
\n {{tableCard.title}}\n\n\n \n \n \n \n\n \n
"); +$templateCache.put("/main/templates/mdtCheckboxColumnFilter.html","
\n
\n \n
\n Sort A-Z \n
\n\n
\n Select all - Clear\n\n
{{selectedItems.length}} Selected
\n
\n\n
\n \n {{ transformChip(item) }}\n \n
\n\n
\n Ok\n Cancel\n
\n
\n
\n
\n"); +$templateCache.put("/main/templates/mdtChipsColumnFilter.html","
\n
\n \n
\n Sort A-Z \n
\n\n
\n \n\n \n\n {{transformChip(item)}}\n\n \n No results found.\n \n \n\n \n \n {{transformChip($chip)}}\n \n \n\n \n
\n\n
\n Ok\n Cancel\n
\n
\n
\n
\n"); +$templateCache.put("/main/templates/mdtColumnSelector.html","\n
\n
\n \n
\n Columns\n
\n
\n Select all - Clear\n\n
{{selectedItems.length}} Selected
\n
\n\n
\n \n {{item.columnName}}\n \n
\n\n
\n Ok\n Cancel\n
\n
\n
\n
\n"); +$templateCache.put("/main/templates/mdtDropdownColumnFilter.html","
\n
\n \n
\n Sort A-Z \n
\n\n
\n \n \n \n {{transformChip(item)}}\n \n \n \n
\n\n
\n Ok\n Cancel\n
\n
\n
\n
\n"); +$templateCache.put("/main/templates/mdtGeneratedHeaderCellContent.html","
\n \n \n\n \n \n\n\n \n \n\n
\n {{headerRowData.columnDefinition}}\n\n \n\n \n\n \n
\n
\n {{headerRowData.columnDefinition}}\n\n \n
\n
"); +$templateCache.put("/main/templates/mdtGeneratedHeaderRow.html","\n\n \n \n\n \n \n\n \n\n \n \n\n"); +$templateCache.put("/main/templates/mdtTable.html","\n \n \n\n \n \n \n\n \n \n
\n\n \n\n \n
\n\n \n \n \n
\n\n"); +$templateCache.put("/main/templates/smallEditDialog.html","\n \n
\n \n\n \n \n \n
\n
\n
\n"); +$templateCache.put("/main/templates/cells/generateCell.html","\n\n\n\n\n\n\n"); +$templateCache.put("/main/templates/cells/generateCellValue.html","\n {{headerRowData.columnName}}\n\n\n\n {{headerRowData.columnName}}\n \n"); +$templateCache.put("/main/templates/cells/generateCheckboxCell.html","\n"); +$templateCache.put("/main/templates/cells/generateSortingIcons.html","\n \n\n\n\n \n"); +$templateCache.put("/main/templates/rows/errorIndicator.html","\n \n\n"); +$templateCache.put("/main/templates/rows/generateRows.html","\n\n \n\n \n \n \n\n\n\n\n\n"); +$templateCache.put("/main/templates/rows/generateRowsVirtualRepeat.html","\n\n \n\n \n\n \n \n\n\n\n\n\n"); +$templateCache.put("/main/templates/rows/noResultIndicator.html","\n \n\n");}]); \ No newline at end of file diff --git a/dist/md-data-table.js b/dist/md-data-table.js index e7cbf0d..67def47 100644 --- a/dist/md-data-table.js +++ b/dist/md-data-table.js @@ -394,6 +394,150 @@ .directive('mdtTable', mdtTableDirective); }()); +(function(){ + 'use strict'; + + TableDataStorageFactory.$inject = ['$log', '_']; + function TableDataStorageFactory($log, _){ + + function TableDataStorageService(){ + this.storage = []; + this.header = []; + this.customCells = {}; + } + + TableDataStorageService.prototype.addHeaderCellData = function(ops){ + this.header.push(ops); + }; + + TableDataStorageService.prototype.addRowData = function(explicitRowId, rowArray, className){ + if(!(rowArray instanceof Array)){ + $log.error('`rowArray` parameter should be array'); + return; + } + + this.storage.push({ + rowId: explicitRowId, + optionList: { + selected: false, + deleted: false, + visible: true, + className: className || false + }, + data: rowArray + }); + }; + + TableDataStorageService.prototype.getRowData = function(index){ + if(!this.storage[index]){ + $log.error('row is not exists at index: '+index); + return; + } + + return this.storage[index].data; + }; + + TableDataStorageService.prototype.getRowOptions = function(index){ + if(!this.storage[index]){ + $log.error('row is not exists at index: '+index); + return; + } + + return this.storage[index].optionList; + }; + + TableDataStorageService.prototype.setAllRowsSelected = function(isSelected, isPaginationEnabled){ + if(typeof isSelected === 'undefined'){ + $log.error('`isSelected` parameter is required'); + return; + } + + _.each(this.storage, function(rowData){ + if(isPaginationEnabled) { + if (rowData.optionList.visible) { + rowData.optionList.selected = isSelected ? true : false; + } + }else{ + rowData.optionList.selected = isSelected ? true : false; + } + }); + }; + + TableDataStorageService.prototype.isAnyRowSelected = function(){ + return _.some(this.storage, function(rowData){ + return rowData.optionList.selected === true && rowData.optionList.deleted === false; + }); + }; + + TableDataStorageService.prototype.getNumberOfSelectedRows = function(){ + var res = _.countBy(this.storage, function(rowData){ + return rowData.optionList.selected === true && rowData.optionList.deleted === false ? 'selected' : 'unselected'; + }); + + return res.selected ? res.selected : 0; + }; + + TableDataStorageService.prototype.deleteSelectedRows = function(){ + var deletedRows = []; + + _.each(this.storage, function(rowData){ + if(rowData.optionList.selected && rowData.optionList.deleted === false){ + + if(rowData.rowId){ + deletedRows.push(rowData.rowId); + + //Fallback when no id was specified + } else{ + deletedRows.push(rowData.data); + } + + rowData.optionList.deleted = true; + } + }); + + return deletedRows; + }; + + TableDataStorageService.prototype.getSelectedRows = function(){ + var selectedRows = []; + + _.each(this.storage, function(rowData){ + if(rowData.optionList.selected && rowData.optionList.deleted === false){ + + if(rowData.rowId){ + selectedRows.push(rowData.rowId); + + //Fallback when no id was specified + } else{ + selectedRows.push(rowData.data); + } + } + }); + + return selectedRows; + }; + + TableDataStorageService.prototype.getSavedRowData = function(rowData){ + var rawRowData = []; + + _.each(rowData.data, function(aCell){ + rawRowData.push(aCell.value); + }); + + return rawRowData; + }; + + return { + getInstance: function(){ + return new TableDataStorageService(); + } + }; + } + + angular + .module('mdDataTable') + .factory('TableDataStorageFactory', TableDataStorageFactory); +}()); (function(){ 'use strict'; @@ -455,6 +599,10 @@ return this.totalResultCount; }; + mdtPaginationHelper.prototype.trackBy = function(item, $index) { + return item[(this.rowOptions && this.rowOptions.trackKey)] || $index; + }; + mdtAjaxPaginationHelper.prototype.getRows = function(){ return this.dataStorage.storage; }; @@ -593,8 +741,9 @@ mdtPaginationHelperFactory.$inject = ['PaginatorTypeProvider', '_']; function mdtPaginationHelperFactory(PaginatorTypeProvider, _){ - function mdtPaginationHelper(dataStorage, paginationSetting){ + function mdtPaginationHelper(dataStorage, paginationSetting, rowOptions){ this.paginatorType = PaginatorTypeProvider.ARRAY; + this.rowOptions = rowOptions; this.dataStorage = dataStorage; @@ -641,6 +790,10 @@ return this.dataStorage.storage.length; }; + mdtPaginationHelper.prototype.trackBy = function(item, $index) { + return item[(this.rowOptions && this.rowOptions.trackKey)] || $index; + }; + mdtPaginationHelper.prototype.getRows = function(){ this.calculateVisibleRows(); @@ -675,8 +828,8 @@ }; return { - getInstance: function(dataStorage, isEnabled){ - return new mdtPaginationHelper(dataStorage, isEnabled); + getInstance: function(dataStorage, isEnabled, rowOptions){ + return new mdtPaginationHelper(dataStorage, isEnabled, rowOptions); } }; } @@ -688,150 +841,6 @@ (function(){ 'use strict'; - TableDataStorageFactory.$inject = ['$log', '_']; - function TableDataStorageFactory($log, _){ - - function TableDataStorageService(){ - this.storage = []; - this.header = []; - this.customCells = {}; - } - - TableDataStorageService.prototype.addHeaderCellData = function(ops){ - this.header.push(ops); - }; - - TableDataStorageService.prototype.addRowData = function(explicitRowId, rowArray, className){ - if(!(rowArray instanceof Array)){ - $log.error('`rowArray` parameter should be array'); - return; - } - - this.storage.push({ - rowId: explicitRowId, - optionList: { - selected: false, - deleted: false, - visible: true, - className: className || false - }, - data: rowArray - }); - }; - - TableDataStorageService.prototype.getRowData = function(index){ - if(!this.storage[index]){ - $log.error('row is not exists at index: '+index); - return; - } - - return this.storage[index].data; - }; - - TableDataStorageService.prototype.getRowOptions = function(index){ - if(!this.storage[index]){ - $log.error('row is not exists at index: '+index); - return; - } - - return this.storage[index].optionList; - }; - - TableDataStorageService.prototype.setAllRowsSelected = function(isSelected, isPaginationEnabled){ - if(typeof isSelected === 'undefined'){ - $log.error('`isSelected` parameter is required'); - return; - } - - _.each(this.storage, function(rowData){ - if(isPaginationEnabled) { - if (rowData.optionList.visible) { - rowData.optionList.selected = isSelected ? true : false; - } - }else{ - rowData.optionList.selected = isSelected ? true : false; - } - }); - }; - - TableDataStorageService.prototype.isAnyRowSelected = function(){ - return _.some(this.storage, function(rowData){ - return rowData.optionList.selected === true && rowData.optionList.deleted === false; - }); - }; - - TableDataStorageService.prototype.getNumberOfSelectedRows = function(){ - var res = _.countBy(this.storage, function(rowData){ - return rowData.optionList.selected === true && rowData.optionList.deleted === false ? 'selected' : 'unselected'; - }); - - return res.selected ? res.selected : 0; - }; - - TableDataStorageService.prototype.deleteSelectedRows = function(){ - var deletedRows = []; - - _.each(this.storage, function(rowData){ - if(rowData.optionList.selected && rowData.optionList.deleted === false){ - - if(rowData.rowId){ - deletedRows.push(rowData.rowId); - - //Fallback when no id was specified - } else{ - deletedRows.push(rowData.data); - } - - rowData.optionList.deleted = true; - } - }); - - return deletedRows; - }; - - TableDataStorageService.prototype.getSelectedRows = function(){ - var selectedRows = []; - - _.each(this.storage, function(rowData){ - if(rowData.optionList.selected && rowData.optionList.deleted === false){ - - if(rowData.rowId){ - selectedRows.push(rowData.rowId); - - //Fallback when no id was specified - } else{ - selectedRows.push(rowData.data); - } - } - }); - - return selectedRows; - }; - - TableDataStorageService.prototype.getSavedRowData = function(rowData){ - var rawRowData = []; - - _.each(rowData.data, function(aCell){ - rawRowData.push(aCell.value); - }); - - return rawRowData; - }; - - return { - getInstance: function(){ - return new TableDataStorageService(); - } - }; - } - - angular - .module('mdDataTable') - .factory('TableDataStorageFactory', TableDataStorageFactory); -}()); -(function(){ - 'use strict'; - PaginationFeature.$inject = ['mdtPaginationHelperFactory', 'mdtAjaxPaginationHelperFactory']; function PaginationFeature(mdtPaginationHelperFactory, mdtAjaxPaginationHelperFactory){ var service = this; From 647367af4b7a72c16fbdf1617e72019406d695bb Mon Sep 17 00:00:00 2001 From: Shalimov Date: Fri, 9 Jun 2017 15:04:54 +0300 Subject: [PATCH 2/6] Fix issues with tracker, trackBy rowId --- .../main/factories/mdtAjaxPaginationHelperFactory.js | 4 ++-- app/modules/main/factories/mdtPaginationHelperFactory.js | 2 +- dist/md-data-table.js | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js b/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js index abc0732..f279e74 100644 --- a/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js +++ b/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js @@ -58,8 +58,8 @@ return this.totalResultCount; }; - mdtPaginationHelper.prototype.trackBy = function(item, $index) { - return item[(this.rowOptions && this.rowOptions.trackKey)] || $index; + mdtAjaxPaginationHelper.prototype.trackBy = function(item, $index) { + return item.rowId || $index; }; mdtAjaxPaginationHelper.prototype.getRows = function(){ diff --git a/app/modules/main/factories/mdtPaginationHelperFactory.js b/app/modules/main/factories/mdtPaginationHelperFactory.js index bf4e238..9c7a18b 100644 --- a/app/modules/main/factories/mdtPaginationHelperFactory.js +++ b/app/modules/main/factories/mdtPaginationHelperFactory.js @@ -53,7 +53,7 @@ }; mdtPaginationHelper.prototype.trackBy = function(item, $index) { - return item[(this.rowOptions && this.rowOptions.trackKey)] || $index; + return item.rowId || $index; }; mdtPaginationHelper.prototype.getRows = function(){ diff --git a/dist/md-data-table.js b/dist/md-data-table.js index 67def47..bdc116e 100644 --- a/dist/md-data-table.js +++ b/dist/md-data-table.js @@ -599,8 +599,8 @@ return this.totalResultCount; }; - mdtPaginationHelper.prototype.trackBy = function(item, $index) { - return item[(this.rowOptions && this.rowOptions.trackKey)] || $index; + mdtAjaxPaginationHelper.prototype.trackBy = function(item, $index) { + return item.rowId || $index; }; mdtAjaxPaginationHelper.prototype.getRows = function(){ @@ -791,7 +791,7 @@ }; mdtPaginationHelper.prototype.trackBy = function(item, $index) { - return item[(this.rowOptions && this.rowOptions.trackKey)] || $index; + return item.rowId || $index; }; mdtPaginationHelper.prototype.getRows = function(){ From a75fccd403ec88a7235b0bfd89372fc2f6ebe367 Mon Sep 17 00:00:00 2001 From: Shalimov Date: Fri, 16 Jun 2017 13:12:29 +0300 Subject: [PATCH 3/6] Add onInitTableCallback --- .../main/directives/mdtTableDirective.js | 5 + dist/md-data-table.js | 953 +++++++++--------- 2 files changed, 484 insertions(+), 474 deletions(-) diff --git a/app/modules/main/directives/mdtTableDirective.js b/app/modules/main/directives/mdtTableDirective.js index 64c0857..5448905 100644 --- a/app/modules/main/directives/mdtTableDirective.js +++ b/app/modules/main/directives/mdtTableDirective.js @@ -127,6 +127,7 @@ tableCard: '=', selectableRows: '=', alternateHeaders: '=', + onInitTableCallback: '=', deleteRowCallback: '&', selectedRowCallback: '&', saveRowCallback: '&', @@ -221,6 +222,10 @@ _initEditCellFeature(); _initSelectableRowsFeature(); + if ($scope.onInitTableCallback) { + $scope.onInitTableCallback(ctrl); + } + PaginationFeature.startFeature(ctrl); ColumnSelectorFeature.initFeatureHeaderValues($scope.dataStorage.header, ctrl.columnSelectorFeature); diff --git a/dist/md-data-table.js b/dist/md-data-table.js index bdc116e..993fac7 100644 --- a/dist/md-data-table.js +++ b/dist/md-data-table.js @@ -238,6 +238,7 @@ tableCard: '=', selectableRows: '=', alternateHeaders: '=', + onInitTableCallback: '=', deleteRowCallback: '&', selectedRowCallback: '&', saveRowCallback: '&', @@ -332,6 +333,10 @@ _initEditCellFeature(); _initSelectableRowsFeature(); + if ($scope.onInitTableCallback) { + $scope.onInitTableCallback(ctrl); + } + PaginationFeature.startFeature(ctrl); ColumnSelectorFeature.initFeatureHeaderValues($scope.dataStorage.header, ctrl.columnSelectorFeature); @@ -394,6 +399,155 @@ .directive('mdtTable', mdtTableDirective); }()); +(function(){ + 'use strict'; + + PaginationFeature.$inject = ['mdtPaginationHelperFactory', 'mdtAjaxPaginationHelperFactory']; + function PaginationFeature(mdtPaginationHelperFactory, mdtAjaxPaginationHelperFactory){ + var service = this; + + service.initFeature = initFeature; + service.startFeature = startFeature; + + function initFeature(scope, ctrl){ + if(!scope.mdtRowPaginator){ + ctrl.mdtPaginationHelper = scope.mdtPaginationHelper = mdtPaginationHelperFactory + .getInstance(ctrl.dataStorage, scope.paginatedRows, scope.mdtRow); + }else{ + ctrl.mdtPaginationHelper = scope.mdtPaginationHelper = mdtAjaxPaginationHelperFactory.getInstance({ + dataStorage: ctrl.dataStorage, + paginationSetting: scope.paginatedRows, + mdtRowOptions: scope.mdtRow, + mdtRowPaginatorFunction: scope.mdtRowPaginator, + mdtRowPaginatorErrorMessage: scope.mdtRowPaginatorErrorMessage, + mdtRowPaginatorNoResultsMessage: scope.mdtRowPaginatorNoResultsMessage, + mdtTriggerRequest: scope.mdtTriggerRequest + }); + } + + scope.isPaginationEnabled = function(){ + if(scope.paginatedRows === true || + (scope.paginatedRows && scope.paginatedRows.hasOwnProperty('isEnabled') && scope.paginatedRows.isEnabled === true)){ + return true; + } + + return false; + }; + + ctrl.paginationFeature = { + startPaginationFeature: function() { + if (scope.mdtRowPaginator) { + scope.mdtPaginationHelper.fetchPage(1); + } + } + }; + } + + function startFeature(ctrl){ + ctrl.paginationFeature.startPaginationFeature(); + } + } + + angular + .module('mdDataTable') + .service('PaginationFeature', PaginationFeature); +}()); +(function(){ + 'use strict'; + + SelectableRowsFeatureFactory.$inject = ['$timeout']; + function SelectableRowsFeatureFactory($timeout){ + + function SelectableRowsFeature(params){ + this.$scope = params.$scope; + this.ctrl = params.ctrl; + + this.$scope.onCheckboxChange = _.bind(this.onCheckboxChange, this); + } + + SelectableRowsFeature.prototype.onCheckboxChange = function(){ + var that = this; + // we need to push it to the event loop to make it happen last + // (e.g.: all the elements can be selected before we call the callback) + $timeout(function(){ + that.$scope.selectedRowCallback({ + rows: that.ctrl.dataStorage.getSelectedRows() + }); + },0); + }; + + return { + getInstance: function(params){ + return new SelectableRowsFeature(params); + } + }; + } + + angular + .module('mdDataTable') + .service('SelectableRowsFeature', SelectableRowsFeatureFactory); +}()); +(function(){ + 'use strict'; + + ColumnAlignmentHelper.$inject = ['ColumnOptionProvider']; + function ColumnAlignmentHelper(ColumnOptionProvider){ + var service = this; + service.getColumnAlignClass = getColumnAlignClass; + + function getColumnAlignClass(alignRule) { + if (alignRule === ColumnOptionProvider.ALIGN_RULE.ALIGN_RIGHT) { + return 'rightAlignedColumn'; + } else { + return 'leftAlignedColumn'; + } + } + } + + angular + .module('mdDataTable') + .service('ColumnAlignmentHelper', ColumnAlignmentHelper); +}()); +(function(){ + 'use strict'; + + /** + * @name ColumnOptionProvider + * @returns possible assignable column options you can give + * + * @describe Representing the assignable properties to the columns you can give. + */ + var ColumnOptionProvider = { + ALIGN_RULE : { + ALIGN_LEFT: 'left', + ALIGN_RIGHT: 'right' + } + }; + + angular + .module('mdDataTable') + .value('ColumnOptionProvider', ColumnOptionProvider); +})(); + +(function(){ + 'use strict'; + + /** + * @name PaginatorTypeProvider + * @returns possible values for different type of paginators + * + * @describe Representing the possible paginator types. + */ + var PaginatorTypeProvider = { + AJAX : 'ajax', + ARRAY : 'array' + }; + + angular + .module('mdDataTable') + .value('PaginatorTypeProvider', PaginatorTypeProvider); +})(); + (function(){ 'use strict'; @@ -841,225 +995,76 @@ (function(){ 'use strict'; - PaginationFeature.$inject = ['mdtPaginationHelperFactory', 'mdtAjaxPaginationHelperFactory']; - function PaginationFeature(mdtPaginationHelperFactory, mdtAjaxPaginationHelperFactory){ - var service = this; - - service.initFeature = initFeature; - service.startFeature = startFeature; + /** + * @ngdoc directive + * @name mdtCell + * @restrict E + * @requires mdtTable + * @requires mdtRow + * + * @description + * Representing a cell which should be placed inside `mdt-row` element directive. + * + * @param {boolean=} htmlContent if set to true, then html content can be placed into the content of the directive. + * @param {string=} editableField if set, then content can be editable. + * + * Available modes are: + * + * - "smallEditDialog" - A simple, one-field edit dialog on click + * - "largeEditDialog" - A complex, flexible edit edit dialog on click + * + * @param {string=} editableFieldTitle if set, then it sets the title of the dialog. (only for `largeEditDialog`) + * @param {number=} editableFieldMaxLength if set, then it sets the maximum length of the field. + * + * + * @example + *
+     *  
+     *      
+     *          Product name
+     *          Price
+     *          Details
+     *      
+     *
+     *      
+     *          {{product.name}}
+     *          {{product.price}}
+     *          
+     *              more details
+     *          
+     *      
+     *  
+     * 
+ */ + mdtCellDirective.$inject = ['$interpolate']; + function mdtCellDirective($interpolate){ + return { + restrict: 'E', + replace: true, + transclude: true, + require: '^mdtRow', + link: function($scope, element, attr, mdtRowCtrl, transclude){ - function initFeature(scope, ctrl){ - if(!scope.mdtRowPaginator){ - ctrl.mdtPaginationHelper = scope.mdtPaginationHelper = mdtPaginationHelperFactory - .getInstance(ctrl.dataStorage, scope.paginatedRows, scope.mdtRow); - }else{ - ctrl.mdtPaginationHelper = scope.mdtPaginationHelper = mdtAjaxPaginationHelperFactory.getInstance({ - dataStorage: ctrl.dataStorage, - paginationSetting: scope.paginatedRows, - mdtRowOptions: scope.mdtRow, - mdtRowPaginatorFunction: scope.mdtRowPaginator, - mdtRowPaginatorErrorMessage: scope.mdtRowPaginatorErrorMessage, - mdtRowPaginatorNoResultsMessage: scope.mdtRowPaginatorNoResultsMessage, - mdtTriggerRequest: scope.mdtTriggerRequest - }); - } + var attributes = { + htmlContent: attr.htmlContent ? attr.htmlContent : false, + editableField: attr.editableField ? attr.editableField : false, + editableFieldTitle: attr.editableFieldTitle ? attr.editableFieldTitle : false, + editableFieldMaxLength: attr.editableFieldMaxLength ? attr.editableFieldMaxLength : false + }; - scope.isPaginationEnabled = function(){ - if(scope.paginatedRows === true || - (scope.paginatedRows && scope.paginatedRows.hasOwnProperty('isEnabled') && scope.paginatedRows.isEnabled === true)){ - return true; - } + transclude(function (clone) { - return false; - }; + if(attr.htmlContent){ + mdtRowCtrl.addToRowDataStorage(clone, attributes); + }else{ + //TODO: better idea? + var cellValue = $interpolate(clone.html())($scope.$parent); - ctrl.paginationFeature = { - startPaginationFeature: function() { - if (scope.mdtRowPaginator) { - scope.mdtPaginationHelper.fetchPage(1); + mdtRowCtrl.addToRowDataStorage(cellValue, attributes); } - } - }; - } - - function startFeature(ctrl){ - ctrl.paginationFeature.startPaginationFeature(); - } - } - - angular - .module('mdDataTable') - .service('PaginationFeature', PaginationFeature); -}()); -(function(){ - 'use strict'; - - SelectableRowsFeatureFactory.$inject = ['$timeout']; - function SelectableRowsFeatureFactory($timeout){ - - function SelectableRowsFeature(params){ - this.$scope = params.$scope; - this.ctrl = params.ctrl; - - this.$scope.onCheckboxChange = _.bind(this.onCheckboxChange, this); - } - - SelectableRowsFeature.prototype.onCheckboxChange = function(){ - var that = this; - // we need to push it to the event loop to make it happen last - // (e.g.: all the elements can be selected before we call the callback) - $timeout(function(){ - that.$scope.selectedRowCallback({ - rows: that.ctrl.dataStorage.getSelectedRows() - }); - },0); - }; - - return { - getInstance: function(params){ - return new SelectableRowsFeature(params); - } - }; - } - - angular - .module('mdDataTable') - .service('SelectableRowsFeature', SelectableRowsFeatureFactory); -}()); -(function(){ - 'use strict'; - - ColumnAlignmentHelper.$inject = ['ColumnOptionProvider']; - function ColumnAlignmentHelper(ColumnOptionProvider){ - var service = this; - service.getColumnAlignClass = getColumnAlignClass; - - function getColumnAlignClass(alignRule) { - if (alignRule === ColumnOptionProvider.ALIGN_RULE.ALIGN_RIGHT) { - return 'rightAlignedColumn'; - } else { - return 'leftAlignedColumn'; - } - } - } - - angular - .module('mdDataTable') - .service('ColumnAlignmentHelper', ColumnAlignmentHelper); -}()); -(function(){ - 'use strict'; - - /** - * @name ColumnOptionProvider - * @returns possible assignable column options you can give - * - * @describe Representing the assignable properties to the columns you can give. - */ - var ColumnOptionProvider = { - ALIGN_RULE : { - ALIGN_LEFT: 'left', - ALIGN_RIGHT: 'right' - } - }; - - angular - .module('mdDataTable') - .value('ColumnOptionProvider', ColumnOptionProvider); -})(); - -(function(){ - 'use strict'; - - /** - * @name PaginatorTypeProvider - * @returns possible values for different type of paginators - * - * @describe Representing the possible paginator types. - */ - var PaginatorTypeProvider = { - AJAX : 'ajax', - ARRAY : 'array' - }; - - angular - .module('mdDataTable') - .value('PaginatorTypeProvider', PaginatorTypeProvider); -})(); - -(function(){ - 'use strict'; - - /** - * @ngdoc directive - * @name mdtCell - * @restrict E - * @requires mdtTable - * @requires mdtRow - * - * @description - * Representing a cell which should be placed inside `mdt-row` element directive. - * - * @param {boolean=} htmlContent if set to true, then html content can be placed into the content of the directive. - * @param {string=} editableField if set, then content can be editable. - * - * Available modes are: - * - * - "smallEditDialog" - A simple, one-field edit dialog on click - * - "largeEditDialog" - A complex, flexible edit edit dialog on click - * - * @param {string=} editableFieldTitle if set, then it sets the title of the dialog. (only for `largeEditDialog`) - * @param {number=} editableFieldMaxLength if set, then it sets the maximum length of the field. - * - * - * @example - *
-     *  
-     *      
-     *          Product name
-     *          Price
-     *          Details
-     *      
-     *
-     *      
-     *          {{product.name}}
-     *          {{product.price}}
-     *          
-     *              more details
-     *          
-     *      
-     *  
-     * 
- */ - mdtCellDirective.$inject = ['$interpolate']; - function mdtCellDirective($interpolate){ - return { - restrict: 'E', - replace: true, - transclude: true, - require: '^mdtRow', - link: function($scope, element, attr, mdtRowCtrl, transclude){ - - var attributes = { - htmlContent: attr.htmlContent ? attr.htmlContent : false, - editableField: attr.editableField ? attr.editableField : false, - editableFieldTitle: attr.editableFieldTitle ? attr.editableFieldTitle : false, - editableFieldMaxLength: attr.editableFieldMaxLength ? attr.editableFieldMaxLength : false - }; - - transclude(function (clone) { - - if(attr.htmlContent){ - mdtRowCtrl.addToRowDataStorage(clone, attributes); - }else{ - //TODO: better idea? - var cellValue = $interpolate(clone.html())($scope.$parent); - - mdtRowCtrl.addToRowDataStorage(cellValue, attributes); - } - }); - } - }; + }); + } + }; } angular @@ -1532,8 +1537,7 @@ (function(){ 'use strict'; - ColumnFilterFeature.$inject = ['ColumnSortFeature', 'PaginatorTypeProvider']; - function ColumnFilterFeature(ColumnSortFeature, PaginatorTypeProvider){ + function ColumnSelectorFeature() { var service = this; @@ -1541,61 +1545,161 @@ * This is the first entry point when we initialize the feature. * * The method adds feature-related variable to the passed object. - * The variables gets stored afterwards in the dataStorage for the header cell * - * @param $scope * @param cellDataToStore */ - service.appendHeaderCellData = function($scope, cellDataToStore, dataStorage){ - cellDataToStore.columnFilter = {}; + service.appendHeaderCellData = function(cellDataToStore, columnSelectorFeature, isColumnExcludedFromColumnSelector, hideColumnByDefault) { + if(!columnSelectorFeature.isEnabled){ + return; + } - if($scope.columnFilter && $scope.columnFilter.valuesProviderCallback){ - cellDataToStore.columnFilter.isEnabled = true; - cellDataToStore.columnFilter.filtersApplied = []; - cellDataToStore.columnFilter.valuesProviderCallback = $scope.columnFilter.valuesProviderCallback; - cellDataToStore.columnFilter.valuesTransformerCallback = $scope.columnFilter.valuesTransformerCallback; - cellDataToStore.columnFilter.placeholderText = $scope.columnFilter.placeholderText; - cellDataToStore.columnFilter.type = $scope.columnFilter.filterType || 'chips'; - cellDataToStore.columnFilter.type = $scope.columnFilter.filterType || 'chips'; - cellDataToStore.columnFilter.isActive = false; + cellDataToStore.columnSelectorFeature = {}; - cellDataToStore.columnFilter.setColumnActive = function(bool){ - //first we disable every column filter if any is active - _.each(dataStorage.header, function(headerData){ - if(headerData.columnFilter.isEnabled){ - headerData.columnFilter.isActive = false; - } - }); + if(isColumnExcludedFromColumnSelector){ + cellDataToStore.columnSelectorFeature.isExcluded = true; + }else{ + cellDataToStore.columnSelectorFeature.isExcluded = false; + } - //then we activate ours - cellDataToStore.columnFilter.isActive = bool ? true : false; - } + if(hideColumnByDefault){ + cellDataToStore.columnSelectorFeature.isHidden = true; }else{ - cellDataToStore.columnFilter.isEnabled = false; + cellDataToStore.columnSelectorFeature.isHidden = false; } }; /** - * Generating the needed functions and variables for the header cell which will - * handle the actions of the column filter component. + * This is the first entry point when we initialize the feature. * - * @param $scope - * @param headerData - * @param paginator + * The method adds feature-related variable to the passed object. + * + * @param cellDataToStore */ - service.initGeneratedHeaderCellContent = function($scope, headerData, paginator, dataStorage){ - if(!headerData.columnFilter.isEnabled){ - return; + service.initFeature = function(scope, vm) { + //TODO: backward compatible when there is only a string input + scope.columnSelectorFeature = {}; + + if(scope.tableCard && scope.tableCard.columnSelector){ + scope.columnSelectorFeature.isEnabled = true; + }else{ + scope.columnSelectorFeature.isEnabled = false; } - $scope.columnFilterFeature = {}; + vm.columnSelectorFeature = scope.columnSelectorFeature; + }; - $scope.columnFilterFeature.cancelFilterDialog = function(event){ - if(event){ - event.stopPropagation(); - } + /** + * This is the second entry point when we initialize the feature. + * + * The method adds feature-related variable to the passed header rows array. + * + * @param headerRowsData + */ + service.initFeatureHeaderValues = function(headerRowsData, columnSelectorFeature){ + if(columnSelectorFeature && columnSelectorFeature.isEnabled){ + _.each(headerRowsData, function(item){ + item.columnSelectorFeature.isVisible = !item.columnSelectorFeature.isHidden; + }); + } + }; - headerData.columnFilter.setColumnActive(false); + /** + * Set the position of the panel. It's required to attach it to the outer container + * of the component because otherwise some parts of the panel can became partially or fully hidden + * (e.g.: when table has only one row to show) + */ + service.positionElement = function(element){ + var elementToPosition = element.parent().find('.mdt-column-chooser-button'); + var elementPosition = elementToPosition.offset(); + var rt = ($(window).width() - (elementPosition.left + elementToPosition.outerWidth())); + + var targetMetrics = { + top: elementPosition.top + 55, + right: rt + }; + + element.css('position', 'absolute'); + element.detach().appendTo('body'); + + element.css({ + top: targetMetrics.top + 'px', + right: targetMetrics.right + 'px', + position:'absolute' + }); + } + } + + angular + .module('mdDataTable') + .service('ColumnSelectorFeature', ColumnSelectorFeature); +}()); +(function(){ + 'use strict'; + + ColumnFilterFeature.$inject = ['ColumnSortFeature', 'PaginatorTypeProvider']; + function ColumnFilterFeature(ColumnSortFeature, PaginatorTypeProvider){ + + var service = this; + + /** + * This is the first entry point when we initialize the feature. + * + * The method adds feature-related variable to the passed object. + * The variables gets stored afterwards in the dataStorage for the header cell + * + * @param $scope + * @param cellDataToStore + */ + service.appendHeaderCellData = function($scope, cellDataToStore, dataStorage){ + cellDataToStore.columnFilter = {}; + + if($scope.columnFilter && $scope.columnFilter.valuesProviderCallback){ + cellDataToStore.columnFilter.isEnabled = true; + cellDataToStore.columnFilter.filtersApplied = []; + cellDataToStore.columnFilter.valuesProviderCallback = $scope.columnFilter.valuesProviderCallback; + cellDataToStore.columnFilter.valuesTransformerCallback = $scope.columnFilter.valuesTransformerCallback; + cellDataToStore.columnFilter.placeholderText = $scope.columnFilter.placeholderText; + cellDataToStore.columnFilter.type = $scope.columnFilter.filterType || 'chips'; + cellDataToStore.columnFilter.type = $scope.columnFilter.filterType || 'chips'; + cellDataToStore.columnFilter.isActive = false; + + cellDataToStore.columnFilter.setColumnActive = function(bool){ + //first we disable every column filter if any is active + _.each(dataStorage.header, function(headerData){ + if(headerData.columnFilter.isEnabled){ + headerData.columnFilter.isActive = false; + } + }); + + //then we activate ours + cellDataToStore.columnFilter.isActive = bool ? true : false; + } + }else{ + cellDataToStore.columnFilter.isEnabled = false; + } + }; + + /** + * Generating the needed functions and variables for the header cell which will + * handle the actions of the column filter component. + * + * @param $scope + * @param headerData + * @param paginator + */ + service.initGeneratedHeaderCellContent = function($scope, headerData, paginator, dataStorage){ + if(!headerData.columnFilter.isEnabled){ + return; + } + + $scope.columnFilterFeature = {}; + + $scope.columnFilterFeature.cancelFilterDialog = function(event){ + if(event){ + event.stopPropagation(); + } + + headerData.columnFilter.setColumnActive(false); }; $scope.columnFilterFeature.confirmFilterDialog = function(params){ @@ -1697,105 +1801,6 @@ (function(){ 'use strict'; - function ColumnSelectorFeature() { - - var service = this; - - /** - * This is the first entry point when we initialize the feature. - * - * The method adds feature-related variable to the passed object. - * - * @param cellDataToStore - */ - service.appendHeaderCellData = function(cellDataToStore, columnSelectorFeature, isColumnExcludedFromColumnSelector, hideColumnByDefault) { - if(!columnSelectorFeature.isEnabled){ - return; - } - - cellDataToStore.columnSelectorFeature = {}; - - if(isColumnExcludedFromColumnSelector){ - cellDataToStore.columnSelectorFeature.isExcluded = true; - }else{ - cellDataToStore.columnSelectorFeature.isExcluded = false; - } - - if(hideColumnByDefault){ - cellDataToStore.columnSelectorFeature.isHidden = true; - }else{ - cellDataToStore.columnSelectorFeature.isHidden = false; - } - }; - - /** - * This is the first entry point when we initialize the feature. - * - * The method adds feature-related variable to the passed object. - * - * @param cellDataToStore - */ - service.initFeature = function(scope, vm) { - //TODO: backward compatible when there is only a string input - scope.columnSelectorFeature = {}; - - if(scope.tableCard && scope.tableCard.columnSelector){ - scope.columnSelectorFeature.isEnabled = true; - }else{ - scope.columnSelectorFeature.isEnabled = false; - } - - vm.columnSelectorFeature = scope.columnSelectorFeature; - }; - - /** - * This is the second entry point when we initialize the feature. - * - * The method adds feature-related variable to the passed header rows array. - * - * @param headerRowsData - */ - service.initFeatureHeaderValues = function(headerRowsData, columnSelectorFeature){ - if(columnSelectorFeature && columnSelectorFeature.isEnabled){ - _.each(headerRowsData, function(item){ - item.columnSelectorFeature.isVisible = !item.columnSelectorFeature.isHidden; - }); - } - }; - - /** - * Set the position of the panel. It's required to attach it to the outer container - * of the component because otherwise some parts of the panel can became partially or fully hidden - * (e.g.: when table has only one row to show) - */ - service.positionElement = function(element){ - var elementToPosition = element.parent().find('.mdt-column-chooser-button'); - var elementPosition = elementToPosition.offset(); - var rt = ($(window).width() - (elementPosition.left + elementToPosition.outerWidth())); - - var targetMetrics = { - top: elementPosition.top + 55, - right: rt - }; - - element.css('position', 'absolute'); - element.detach().appendTo('body'); - - element.css({ - top: targetMetrics.top + 'px', - right: targetMetrics.right + 'px', - position:'absolute' - }); - } - } - - angular - .module('mdDataTable') - .service('ColumnSelectorFeature', ColumnSelectorFeature); -}()); -(function(){ - 'use strict'; - ColumnSortFeature.$inject = ['ColumnSortDirectionProvider']; function ColumnSortFeature(ColumnSortDirectionProvider) { @@ -2036,6 +2041,127 @@ (function() { 'use strict'; + mdtColumnSelectorDirective.$inject = ['ColumnSelectorFeature', 'ColumnFilterFeature', 'PaginatorTypeProvider']; + function mdtColumnSelectorDirective(ColumnSelectorFeature, ColumnFilterFeature, PaginatorTypeProvider){ + return{ + restrict: 'E', + templateUrl: '/main/templates/mdtColumnSelector.html', + scope: true, + link: function($scope, element){ + ColumnSelectorFeature.positionElement(element); + + $scope.headerRowsData = _.map($scope.dataStorage.header, function(item){ + //excluded content should also be in, since we use the index of the array to apply the changes. Do not exclude them. + + return { + columnName: item.columnName, + isVisible: item.columnSelectorFeature.isVisible, + isExcluded: item.columnSelectorFeature.isExcluded + }; + }); + + //destroying scope doesn't remove element, since it belongs to the body directly + $scope.$on('$destroy', function(){ + element.remove(); + }); + + $scope.checked = function (item) { + return item.isVisible; + }; + + $scope.toggle = function (item) { + item.isVisible = !item.isVisible; + }; + + $scope.selectAll = function($event){ + $event.preventDefault(); + + _.each($scope.headerRowsData, function(item){ + if(item.isExcluded){ + return; + } + + item.isVisible = true; + }); + }; + + $scope.clearAll = function($event){ + $event.preventDefault(); + + _.each($scope.headerRowsData, function(item){ + if(item.isExcluded){ + return; + } + + item.isVisible = false; + }); + }; + + $scope.isAllSelected = function(){ + var result = _.find($scope.headerRowsData, function(item){ + if(item.isExcluded){ + return false; + } + + return item.isVisible === false; + }); + + return result ? false : true; + }; + + $scope.isNothingSelected = function(){ + var result = _.find($scope.headerRowsData, function(item){ + if(item.isExcluded){ + return false; + } + + return item.isVisible === true; + }); + + return result ? false : true; + }; + + $scope.confirmCallback = function(params){ + var paginator = params.paginator; + var isAnyResetHappened = false; + + _.each($scope.dataStorage.header, function(item, index){ + item.columnSelectorFeature.isVisible = $scope.headerRowsData[index].isVisible; + + if(!item.columnSelectorFeature.isVisible){ + var result = ColumnFilterFeature.resetFiltersForColumn($scope.dataStorage, index); + + if(result){ + isAnyResetHappened = true; + } + } + }); + + $scope.columnSelectorFeature.isActive = false; + + if(isAnyResetHappened){ + if(paginator.paginatorType === PaginatorTypeProvider.AJAX){ + paginator.getFirstPage(); + }else{ + // no support for non-ajax yet + } + } + }; + + $scope.cancelCallback = function(){ + $scope.columnSelectorFeature.isActive = false; + }; + } + } + } + + angular + .module('mdDataTable') + .directive('mdtColumnSelector', mdtColumnSelectorDirective); +})(); +(function() { + 'use strict'; + mdtCheckboxColumnFilterDirective.$inject = ['_', 'ColumnFilterFeature', 'ColumnSortFeature', 'ColumnSortDirectionProvider']; function mdtCheckboxColumnFilterDirective(_, ColumnFilterFeature, ColumnSortFeature, ColumnSortDirectionProvider){ return{ @@ -2247,127 +2373,6 @@ .module('mdDataTable') .directive('mdtDropdownColumnFilter', mdtDropdownColumnFilterDirective); })(); -(function() { - 'use strict'; - - mdtColumnSelectorDirective.$inject = ['ColumnSelectorFeature', 'ColumnFilterFeature', 'PaginatorTypeProvider']; - function mdtColumnSelectorDirective(ColumnSelectorFeature, ColumnFilterFeature, PaginatorTypeProvider){ - return{ - restrict: 'E', - templateUrl: '/main/templates/mdtColumnSelector.html', - scope: true, - link: function($scope, element){ - ColumnSelectorFeature.positionElement(element); - - $scope.headerRowsData = _.map($scope.dataStorage.header, function(item){ - //excluded content should also be in, since we use the index of the array to apply the changes. Do not exclude them. - - return { - columnName: item.columnName, - isVisible: item.columnSelectorFeature.isVisible, - isExcluded: item.columnSelectorFeature.isExcluded - }; - }); - - //destroying scope doesn't remove element, since it belongs to the body directly - $scope.$on('$destroy', function(){ - element.remove(); - }); - - $scope.checked = function (item) { - return item.isVisible; - }; - - $scope.toggle = function (item) { - item.isVisible = !item.isVisible; - }; - - $scope.selectAll = function($event){ - $event.preventDefault(); - - _.each($scope.headerRowsData, function(item){ - if(item.isExcluded){ - return; - } - - item.isVisible = true; - }); - }; - - $scope.clearAll = function($event){ - $event.preventDefault(); - - _.each($scope.headerRowsData, function(item){ - if(item.isExcluded){ - return; - } - - item.isVisible = false; - }); - }; - - $scope.isAllSelected = function(){ - var result = _.find($scope.headerRowsData, function(item){ - if(item.isExcluded){ - return false; - } - - return item.isVisible === false; - }); - - return result ? false : true; - }; - - $scope.isNothingSelected = function(){ - var result = _.find($scope.headerRowsData, function(item){ - if(item.isExcluded){ - return false; - } - - return item.isVisible === true; - }); - - return result ? false : true; - }; - - $scope.confirmCallback = function(params){ - var paginator = params.paginator; - var isAnyResetHappened = false; - - _.each($scope.dataStorage.header, function(item, index){ - item.columnSelectorFeature.isVisible = $scope.headerRowsData[index].isVisible; - - if(!item.columnSelectorFeature.isVisible){ - var result = ColumnFilterFeature.resetFiltersForColumn($scope.dataStorage, index); - - if(result){ - isAnyResetHappened = true; - } - } - }); - - $scope.columnSelectorFeature.isActive = false; - - if(isAnyResetHappened){ - if(paginator.paginatorType === PaginatorTypeProvider.AJAX){ - paginator.getFirstPage(); - }else{ - // no support for non-ajax yet - } - } - }; - - $scope.cancelCallback = function(){ - $scope.columnSelectorFeature.isActive = false; - }; - } - } - } - - angular - .module('mdDataTable') - .directive('mdtColumnSelector', mdtColumnSelectorDirective); -})(); (function(){ 'use strict'; From d8b13ec6a96411689c2a7f6fd52367b3bf89d181 Mon Sep 17 00:00:00 2001 From: Shalimov Date: Fri, 16 Jun 2017 13:50:25 +0300 Subject: [PATCH 4/6] update md-data --- .../main/directives/mdtTableDirective.js | 2 +- dist/md-data-table.js | 594 +++++++++--------- 2 files changed, 298 insertions(+), 298 deletions(-) diff --git a/app/modules/main/directives/mdtTableDirective.js b/app/modules/main/directives/mdtTableDirective.js index 5448905..ccb1aed 100644 --- a/app/modules/main/directives/mdtTableDirective.js +++ b/app/modules/main/directives/mdtTableDirective.js @@ -223,7 +223,7 @@ _initSelectableRowsFeature(); if ($scope.onInitTableCallback) { - $scope.onInitTableCallback(ctrl); + $scope.onInitTableCallback(ctrl, $scope); } PaginationFeature.startFeature(ctrl); diff --git a/dist/md-data-table.js b/dist/md-data-table.js index 993fac7..5e39c48 100644 --- a/dist/md-data-table.js +++ b/dist/md-data-table.js @@ -334,7 +334,7 @@ _initSelectableRowsFeature(); if ($scope.onInitTableCallback) { - $scope.onInitTableCallback(ctrl); + $scope.onInitTableCallback(ctrl, $scope); } PaginationFeature.startFeature(ctrl); @@ -487,67 +487,6 @@ .module('mdDataTable') .service('SelectableRowsFeature', SelectableRowsFeatureFactory); }()); -(function(){ - 'use strict'; - - ColumnAlignmentHelper.$inject = ['ColumnOptionProvider']; - function ColumnAlignmentHelper(ColumnOptionProvider){ - var service = this; - service.getColumnAlignClass = getColumnAlignClass; - - function getColumnAlignClass(alignRule) { - if (alignRule === ColumnOptionProvider.ALIGN_RULE.ALIGN_RIGHT) { - return 'rightAlignedColumn'; - } else { - return 'leftAlignedColumn'; - } - } - } - - angular - .module('mdDataTable') - .service('ColumnAlignmentHelper', ColumnAlignmentHelper); -}()); -(function(){ - 'use strict'; - - /** - * @name ColumnOptionProvider - * @returns possible assignable column options you can give - * - * @describe Representing the assignable properties to the columns you can give. - */ - var ColumnOptionProvider = { - ALIGN_RULE : { - ALIGN_LEFT: 'left', - ALIGN_RIGHT: 'right' - } - }; - - angular - .module('mdDataTable') - .value('ColumnOptionProvider', ColumnOptionProvider); -})(); - -(function(){ - 'use strict'; - - /** - * @name PaginatorTypeProvider - * @returns possible values for different type of paginators - * - * @describe Representing the possible paginator types. - */ - var PaginatorTypeProvider = { - AJAX : 'ajax', - ARRAY : 'array' - }; - - angular - .module('mdDataTable') - .value('PaginatorTypeProvider', PaginatorTypeProvider); -})(); - (function(){ 'use strict'; @@ -992,6 +931,67 @@ .module('mdDataTable') .service('mdtPaginationHelperFactory', mdtPaginationHelperFactory); }()); +(function(){ + 'use strict'; + + ColumnAlignmentHelper.$inject = ['ColumnOptionProvider']; + function ColumnAlignmentHelper(ColumnOptionProvider){ + var service = this; + service.getColumnAlignClass = getColumnAlignClass; + + function getColumnAlignClass(alignRule) { + if (alignRule === ColumnOptionProvider.ALIGN_RULE.ALIGN_RIGHT) { + return 'rightAlignedColumn'; + } else { + return 'leftAlignedColumn'; + } + } + } + + angular + .module('mdDataTable') + .service('ColumnAlignmentHelper', ColumnAlignmentHelper); +}()); +(function(){ + 'use strict'; + + /** + * @name ColumnOptionProvider + * @returns possible assignable column options you can give + * + * @describe Representing the assignable properties to the columns you can give. + */ + var ColumnOptionProvider = { + ALIGN_RULE : { + ALIGN_LEFT: 'left', + ALIGN_RIGHT: 'right' + } + }; + + angular + .module('mdDataTable') + .value('ColumnOptionProvider', ColumnOptionProvider); +})(); + +(function(){ + 'use strict'; + + /** + * @name PaginatorTypeProvider + * @returns possible values for different type of paginators + * + * @describe Representing the possible paginator types. + */ + var PaginatorTypeProvider = { + AJAX : 'ajax', + ARRAY : 'array' + }; + + angular + .module('mdDataTable') + .value('PaginatorTypeProvider', PaginatorTypeProvider); +})(); + (function(){ 'use strict'; @@ -1537,105 +1537,6 @@ (function(){ 'use strict'; - function ColumnSelectorFeature() { - - var service = this; - - /** - * This is the first entry point when we initialize the feature. - * - * The method adds feature-related variable to the passed object. - * - * @param cellDataToStore - */ - service.appendHeaderCellData = function(cellDataToStore, columnSelectorFeature, isColumnExcludedFromColumnSelector, hideColumnByDefault) { - if(!columnSelectorFeature.isEnabled){ - return; - } - - cellDataToStore.columnSelectorFeature = {}; - - if(isColumnExcludedFromColumnSelector){ - cellDataToStore.columnSelectorFeature.isExcluded = true; - }else{ - cellDataToStore.columnSelectorFeature.isExcluded = false; - } - - if(hideColumnByDefault){ - cellDataToStore.columnSelectorFeature.isHidden = true; - }else{ - cellDataToStore.columnSelectorFeature.isHidden = false; - } - }; - - /** - * This is the first entry point when we initialize the feature. - * - * The method adds feature-related variable to the passed object. - * - * @param cellDataToStore - */ - service.initFeature = function(scope, vm) { - //TODO: backward compatible when there is only a string input - scope.columnSelectorFeature = {}; - - if(scope.tableCard && scope.tableCard.columnSelector){ - scope.columnSelectorFeature.isEnabled = true; - }else{ - scope.columnSelectorFeature.isEnabled = false; - } - - vm.columnSelectorFeature = scope.columnSelectorFeature; - }; - - /** - * This is the second entry point when we initialize the feature. - * - * The method adds feature-related variable to the passed header rows array. - * - * @param headerRowsData - */ - service.initFeatureHeaderValues = function(headerRowsData, columnSelectorFeature){ - if(columnSelectorFeature && columnSelectorFeature.isEnabled){ - _.each(headerRowsData, function(item){ - item.columnSelectorFeature.isVisible = !item.columnSelectorFeature.isHidden; - }); - } - }; - - /** - * Set the position of the panel. It's required to attach it to the outer container - * of the component because otherwise some parts of the panel can became partially or fully hidden - * (e.g.: when table has only one row to show) - */ - service.positionElement = function(element){ - var elementToPosition = element.parent().find('.mdt-column-chooser-button'); - var elementPosition = elementToPosition.offset(); - var rt = ($(window).width() - (elementPosition.left + elementToPosition.outerWidth())); - - var targetMetrics = { - top: elementPosition.top + 55, - right: rt - }; - - element.css('position', 'absolute'); - element.detach().appendTo('body'); - - element.css({ - top: targetMetrics.top + 'px', - right: targetMetrics.right + 'px', - position:'absolute' - }); - } - } - - angular - .module('mdDataTable') - .service('ColumnSelectorFeature', ColumnSelectorFeature); -}()); -(function(){ - 'use strict'; - ColumnFilterFeature.$inject = ['ColumnSortFeature', 'PaginatorTypeProvider']; function ColumnFilterFeature(ColumnSortFeature, PaginatorTypeProvider){ @@ -1801,8 +1702,7 @@ (function(){ 'use strict'; - ColumnSortFeature.$inject = ['ColumnSortDirectionProvider']; - function ColumnSortFeature(ColumnSortDirectionProvider) { + function ColumnSelectorFeature() { var service = this; @@ -1813,27 +1713,127 @@ * * @param cellDataToStore */ - service.appendHeaderCellData = function(cellDataToStore, columnSortOptions) { - cellDataToStore.columnSort = {}; + service.appendHeaderCellData = function(cellDataToStore, columnSelectorFeature, isColumnExcludedFromColumnSelector, hideColumnByDefault) { + if(!columnSelectorFeature.isEnabled){ + return; + } - if(columnSortOptions){ - cellDataToStore.columnSort.isEnabled = true; - cellDataToStore.columnSort.sort = false; - cellDataToStore.columnSort.comparator = columnSortOptions.comparator ? columnSortOptions.comparator : false; + cellDataToStore.columnSelectorFeature = {}; + + if(isColumnExcludedFromColumnSelector){ + cellDataToStore.columnSelectorFeature.isExcluded = true; }else{ - cellDataToStore.columnSort.isEnabled = false; + cellDataToStore.columnSelectorFeature.isExcluded = false; + } + + if(hideColumnByDefault){ + cellDataToStore.columnSelectorFeature.isHidden = true; + }else{ + cellDataToStore.columnSelectorFeature.isHidden = false; } }; /** - * Sets the sorting direction for the passed header + * This is the first entry point when we initialize the feature. * - * @param headerRowData - * @param valueToSet - * @param dataStorage + * The method adds feature-related variable to the passed object. + * + * @param cellDataToStore */ - service.setHeaderSort = function(headerRowData, valueToSet, dataStorage){ - if(!valueToSet){ + service.initFeature = function(scope, vm) { + //TODO: backward compatible when there is only a string input + scope.columnSelectorFeature = {}; + + if(scope.tableCard && scope.tableCard.columnSelector){ + scope.columnSelectorFeature.isEnabled = true; + }else{ + scope.columnSelectorFeature.isEnabled = false; + } + + vm.columnSelectorFeature = scope.columnSelectorFeature; + }; + + /** + * This is the second entry point when we initialize the feature. + * + * The method adds feature-related variable to the passed header rows array. + * + * @param headerRowsData + */ + service.initFeatureHeaderValues = function(headerRowsData, columnSelectorFeature){ + if(columnSelectorFeature && columnSelectorFeature.isEnabled){ + _.each(headerRowsData, function(item){ + item.columnSelectorFeature.isVisible = !item.columnSelectorFeature.isHidden; + }); + } + }; + + /** + * Set the position of the panel. It's required to attach it to the outer container + * of the component because otherwise some parts of the panel can became partially or fully hidden + * (e.g.: when table has only one row to show) + */ + service.positionElement = function(element){ + var elementToPosition = element.parent().find('.mdt-column-chooser-button'); + var elementPosition = elementToPosition.offset(); + var rt = ($(window).width() - (elementPosition.left + elementToPosition.outerWidth())); + + var targetMetrics = { + top: elementPosition.top + 55, + right: rt + }; + + element.css('position', 'absolute'); + element.detach().appendTo('body'); + + element.css({ + top: targetMetrics.top + 'px', + right: targetMetrics.right + 'px', + position:'absolute' + }); + } + } + + angular + .module('mdDataTable') + .service('ColumnSelectorFeature', ColumnSelectorFeature); +}()); +(function(){ + 'use strict'; + + ColumnSortFeature.$inject = ['ColumnSortDirectionProvider']; + function ColumnSortFeature(ColumnSortDirectionProvider) { + + var service = this; + + /** + * This is the first entry point when we initialize the feature. + * + * The method adds feature-related variable to the passed object. + * + * @param cellDataToStore + */ + service.appendHeaderCellData = function(cellDataToStore, columnSortOptions) { + cellDataToStore.columnSort = {}; + + if(columnSortOptions){ + cellDataToStore.columnSort.isEnabled = true; + cellDataToStore.columnSort.sort = false; + cellDataToStore.columnSort.comparator = columnSortOptions.comparator ? columnSortOptions.comparator : false; + }else{ + cellDataToStore.columnSort.isEnabled = false; + } + }; + + /** + * Sets the sorting direction for the passed header + * + * @param headerRowData + * @param valueToSet + * @param dataStorage + */ + service.setHeaderSort = function(headerRowData, valueToSet, dataStorage){ + if(!valueToSet){ return; } @@ -2041,127 +2041,6 @@ (function() { 'use strict'; - mdtColumnSelectorDirective.$inject = ['ColumnSelectorFeature', 'ColumnFilterFeature', 'PaginatorTypeProvider']; - function mdtColumnSelectorDirective(ColumnSelectorFeature, ColumnFilterFeature, PaginatorTypeProvider){ - return{ - restrict: 'E', - templateUrl: '/main/templates/mdtColumnSelector.html', - scope: true, - link: function($scope, element){ - ColumnSelectorFeature.positionElement(element); - - $scope.headerRowsData = _.map($scope.dataStorage.header, function(item){ - //excluded content should also be in, since we use the index of the array to apply the changes. Do not exclude them. - - return { - columnName: item.columnName, - isVisible: item.columnSelectorFeature.isVisible, - isExcluded: item.columnSelectorFeature.isExcluded - }; - }); - - //destroying scope doesn't remove element, since it belongs to the body directly - $scope.$on('$destroy', function(){ - element.remove(); - }); - - $scope.checked = function (item) { - return item.isVisible; - }; - - $scope.toggle = function (item) { - item.isVisible = !item.isVisible; - }; - - $scope.selectAll = function($event){ - $event.preventDefault(); - - _.each($scope.headerRowsData, function(item){ - if(item.isExcluded){ - return; - } - - item.isVisible = true; - }); - }; - - $scope.clearAll = function($event){ - $event.preventDefault(); - - _.each($scope.headerRowsData, function(item){ - if(item.isExcluded){ - return; - } - - item.isVisible = false; - }); - }; - - $scope.isAllSelected = function(){ - var result = _.find($scope.headerRowsData, function(item){ - if(item.isExcluded){ - return false; - } - - return item.isVisible === false; - }); - - return result ? false : true; - }; - - $scope.isNothingSelected = function(){ - var result = _.find($scope.headerRowsData, function(item){ - if(item.isExcluded){ - return false; - } - - return item.isVisible === true; - }); - - return result ? false : true; - }; - - $scope.confirmCallback = function(params){ - var paginator = params.paginator; - var isAnyResetHappened = false; - - _.each($scope.dataStorage.header, function(item, index){ - item.columnSelectorFeature.isVisible = $scope.headerRowsData[index].isVisible; - - if(!item.columnSelectorFeature.isVisible){ - var result = ColumnFilterFeature.resetFiltersForColumn($scope.dataStorage, index); - - if(result){ - isAnyResetHappened = true; - } - } - }); - - $scope.columnSelectorFeature.isActive = false; - - if(isAnyResetHappened){ - if(paginator.paginatorType === PaginatorTypeProvider.AJAX){ - paginator.getFirstPage(); - }else{ - // no support for non-ajax yet - } - } - }; - - $scope.cancelCallback = function(){ - $scope.columnSelectorFeature.isActive = false; - }; - } - } - } - - angular - .module('mdDataTable') - .directive('mdtColumnSelector', mdtColumnSelectorDirective); -})(); -(function() { - 'use strict'; - mdtCheckboxColumnFilterDirective.$inject = ['_', 'ColumnFilterFeature', 'ColumnSortFeature', 'ColumnSortDirectionProvider']; function mdtCheckboxColumnFilterDirective(_, ColumnFilterFeature, ColumnSortFeature, ColumnSortDirectionProvider){ return{ @@ -2373,6 +2252,127 @@ .module('mdDataTable') .directive('mdtDropdownColumnFilter', mdtDropdownColumnFilterDirective); })(); +(function() { + 'use strict'; + + mdtColumnSelectorDirective.$inject = ['ColumnSelectorFeature', 'ColumnFilterFeature', 'PaginatorTypeProvider']; + function mdtColumnSelectorDirective(ColumnSelectorFeature, ColumnFilterFeature, PaginatorTypeProvider){ + return{ + restrict: 'E', + templateUrl: '/main/templates/mdtColumnSelector.html', + scope: true, + link: function($scope, element){ + ColumnSelectorFeature.positionElement(element); + + $scope.headerRowsData = _.map($scope.dataStorage.header, function(item){ + //excluded content should also be in, since we use the index of the array to apply the changes. Do not exclude them. + + return { + columnName: item.columnName, + isVisible: item.columnSelectorFeature.isVisible, + isExcluded: item.columnSelectorFeature.isExcluded + }; + }); + + //destroying scope doesn't remove element, since it belongs to the body directly + $scope.$on('$destroy', function(){ + element.remove(); + }); + + $scope.checked = function (item) { + return item.isVisible; + }; + + $scope.toggle = function (item) { + item.isVisible = !item.isVisible; + }; + + $scope.selectAll = function($event){ + $event.preventDefault(); + + _.each($scope.headerRowsData, function(item){ + if(item.isExcluded){ + return; + } + + item.isVisible = true; + }); + }; + + $scope.clearAll = function($event){ + $event.preventDefault(); + + _.each($scope.headerRowsData, function(item){ + if(item.isExcluded){ + return; + } + + item.isVisible = false; + }); + }; + + $scope.isAllSelected = function(){ + var result = _.find($scope.headerRowsData, function(item){ + if(item.isExcluded){ + return false; + } + + return item.isVisible === false; + }); + + return result ? false : true; + }; + + $scope.isNothingSelected = function(){ + var result = _.find($scope.headerRowsData, function(item){ + if(item.isExcluded){ + return false; + } + + return item.isVisible === true; + }); + + return result ? false : true; + }; + + $scope.confirmCallback = function(params){ + var paginator = params.paginator; + var isAnyResetHappened = false; + + _.each($scope.dataStorage.header, function(item, index){ + item.columnSelectorFeature.isVisible = $scope.headerRowsData[index].isVisible; + + if(!item.columnSelectorFeature.isVisible){ + var result = ColumnFilterFeature.resetFiltersForColumn($scope.dataStorage, index); + + if(result){ + isAnyResetHappened = true; + } + } + }); + + $scope.columnSelectorFeature.isActive = false; + + if(isAnyResetHappened){ + if(paginator.paginatorType === PaginatorTypeProvider.AJAX){ + paginator.getFirstPage(); + }else{ + // no support for non-ajax yet + } + } + }; + + $scope.cancelCallback = function(){ + $scope.columnSelectorFeature.isActive = false; + }; + } + } + } + + angular + .module('mdDataTable') + .directive('mdtColumnSelector', mdtColumnSelectorDirective); +})(); (function(){ 'use strict'; From 389ea4f3f2a2497ecbb130f13d9cba6e6010bbba Mon Sep 17 00:00:00 2001 From: Shalimov Date: Fri, 6 Jul 2018 12:15:06 +0300 Subject: [PATCH 5/6] update ajax --- dist/md-data-table.js | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/dist/md-data-table.js b/dist/md-data-table.js index 5e39c48..ddfaf15 100644 --- a/dist/md-data-table.js +++ b/dist/md-data-table.js @@ -757,6 +757,7 @@ that.isLoadError = false; that.isLoading = false; + that.page = page; }, function(){ that.dataStorage.storage = []; diff --git a/package.json b/package.json index 2bf1455..f1a8e44 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "md-data-table", - "version": "2.2.0", + "version": "2.2.6", "author": "Istvan Fodor ", "registry": "github", "repository": { From 543973b22955994fa1775e59b9f382f8f4f404ea Mon Sep 17 00:00:00 2001 From: Shalimov Date: Fri, 6 Jul 2018 12:26:38 +0300 Subject: [PATCH 6/6] fix pagination --- dist/md-data-table.js | 6 ++++-- package.json | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/dist/md-data-table.js b/dist/md-data-table.js index ddfaf15..4f3e384 100644 --- a/dist/md-data-table.js +++ b/dist/md-data-table.js @@ -732,7 +732,7 @@ return this.page > 1; }; - mdtAjaxPaginationHelper.prototype.fetchPage = function(page){ + mdtAjaxPaginationHelper.prototype.fetchPage = function(page, allowChangePage){ this.isLoading = true; var that = this; @@ -757,8 +757,10 @@ that.isLoadError = false; that.isLoading = false; - that.page = page; + if (allowChangePage) { + that.page = page; + } }, function(){ that.dataStorage.storage = []; diff --git a/package.json b/package.json index f1a8e44..8e794b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "md-data-table", - "version": "2.2.6", + "version": "2.2.7", "author": "Istvan Fodor ", "registry": "github", "repository": {