diff --git a/app/modules/main/directives/mdtTableDirective.js b/app/modules/main/directives/mdtTableDirective.js index 64c0857..ccb1aed 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, $scope); + } + PaginationFeature.startFeature(ctrl); ColumnSelectorFeature.initFeatureHeaderValues($scope.dataStorage.header, ctrl.columnSelectorFeature); diff --git a/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js b/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js index 1bd3a92..f279e74 100644 --- a/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js +++ b/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js @@ -58,6 +58,10 @@ return this.totalResultCount; }; + mdtAjaxPaginationHelper.prototype.trackBy = function(item, $index) { + return item.rowId || $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..9c7a18b 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.rowId || $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..4f3e384 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, $scope); + } + PaginationFeature.startFeature(ctrl); ColumnSelectorFeature.initFeatureHeaderValues($scope.dataStorage.header, ctrl.columnSelectorFeature); @@ -394,6 +399,238 @@ .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'; + + 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 +692,10 @@ return this.totalResultCount; }; + mdtAjaxPaginationHelper.prototype.trackBy = function(item, $index) { + return item.rowId || $index; + }; + mdtAjaxPaginationHelper.prototype.getRows = function(){ return this.dataStorage.storage; }; @@ -491,7 +732,7 @@ return this.page > 1; }; - mdtAjaxPaginationHelper.prototype.fetchPage = function(page){ + mdtAjaxPaginationHelper.prototype.fetchPage = function(page, allowChangePage){ this.isLoading = true; var that = this; @@ -517,6 +758,9 @@ that.isLoadError = false; that.isLoading = false; + if (allowChangePage) { + that.page = page; + } }, function(){ that.dataStorage.storage = []; @@ -593,8 +837,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 +886,10 @@ return this.dataStorage.storage.length; }; + mdtPaginationHelper.prototype.trackBy = function(item, $index) { + return item.rowId || $index; + }; + mdtPaginationHelper.prototype.getRows = function(){ this.calculateVisibleRows(); @@ -675,8 +924,8 @@ }; return { - getInstance: function(dataStorage, isEnabled){ - return new mdtPaginationHelper(dataStorage, isEnabled); + getInstance: function(dataStorage, isEnabled, rowOptions){ + return new mdtPaginationHelper(dataStorage, isEnabled, rowOptions); } }; } @@ -688,238 +937,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; - - 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; diff --git a/package.json b/package.json index 2bf1455..8e794b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "md-data-table", - "version": "2.2.0", + "version": "2.2.7", "author": "Istvan Fodor ", "registry": "github", "repository": {