From 82459c2364a604f9000e292f161c1a11f07cd8ad Mon Sep 17 00:00:00 2001 From: Ries van Twisk Date: Sun, 22 Jan 2017 13:18:15 +0100 Subject: [PATCH 1/3] Fixes on the last page x of x mis-match. --- app/modules/main/factories/mdtAjaxPaginationHelperFactory.js | 2 +- app/modules/main/factories/mdtPaginationHelperFactory.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js b/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js index 1bd3a92..bd2e836 100644 --- a/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js +++ b/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js @@ -47,7 +47,7 @@ mdtAjaxPaginationHelper.prototype.getEndRowIndex = function(){ var lastItem = this.getStartRowIndex() + this.rowsPerPage - 1; - if(this.totalResultCount < lastItem){ + if((this.totalResultCount - 1) < lastItem){ return this.totalResultCount - 1; } diff --git a/app/modules/main/factories/mdtPaginationHelperFactory.js b/app/modules/main/factories/mdtPaginationHelperFactory.js index dfc0d6a..7600a61 100644 --- a/app/modules/main/factories/mdtPaginationHelperFactory.js +++ b/app/modules/main/factories/mdtPaginationHelperFactory.js @@ -40,7 +40,7 @@ mdtPaginationHelper.prototype.getEndRowIndex = function(){ var lastItem = this.getStartRowIndex() + this.rowsPerPage-1; - if(this.dataStorage.storage.length < lastItem){ + if((this.dataStorage.storage.length - 1) < lastItem){ return this.dataStorage.storage.length - 1; } From f600cc8e9f9af055d1510c76488097d9194d99fb Mon Sep 17 00:00:00 2001 From: Ries van Twisk Date: Tue, 7 Feb 2017 12:58:05 +0100 Subject: [PATCH 2/3] When fetchpage is called, store the current page when given --- .../mdtAjaxPaginationHelperFactory.js | 11 +- dist/md-data-table-templates.js | 42 +-- dist/md-data-table.js | 299 +++++++++--------- 3 files changed, 178 insertions(+), 174 deletions(-) diff --git a/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js b/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js index bd2e836..051a60b 100644 --- a/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js +++ b/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js @@ -66,7 +66,6 @@ var that = this; if(this.hasPreviousPage()){ this.fetchPage(this.page-1).then(function(){ - that.page--; }); } }; @@ -75,15 +74,12 @@ var that = this; if(this.hasNextPage()){ this.fetchPage(this.page+1).then(function(){ - that.page++; }); } }; mdtAjaxPaginationHelper.prototype.getFirstPage = function(){ - this.page = 1; - - this.fetchPage(this.page); + this.fetchPage(1); }; mdtAjaxPaginationHelper.prototype.hasNextPage = function(){ @@ -95,6 +91,11 @@ }; mdtAjaxPaginationHelper.prototype.fetchPage = function(page){ + if (page) { + this.page = page; + } else { + page = this.page; + } this.isLoading = true; var that = this; diff --git a/dist/md-data-table-templates.js b/dist/md-data-table-templates.js index 213a0f7..77b70ae 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..e042197 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'; @@ -444,7 +588,7 @@ mdtAjaxPaginationHelper.prototype.getEndRowIndex = function(){ var lastItem = this.getStartRowIndex() + this.rowsPerPage - 1; - if(this.totalResultCount < lastItem){ + if((this.totalResultCount - 1) < lastItem){ return this.totalResultCount - 1; } @@ -463,7 +607,6 @@ var that = this; if(this.hasPreviousPage()){ this.fetchPage(this.page-1).then(function(){ - that.page--; }); } }; @@ -472,7 +615,6 @@ var that = this; if(this.hasNextPage()){ this.fetchPage(this.page+1).then(function(){ - that.page++; }); } }; @@ -492,6 +634,11 @@ }; mdtAjaxPaginationHelper.prototype.fetchPage = function(page){ + if (page) { + this.page = page; + } else { + page = this.page; + } this.isLoading = true; var that = this; @@ -630,7 +777,7 @@ mdtPaginationHelper.prototype.getEndRowIndex = function(){ var lastItem = this.getStartRowIndex() + this.rowsPerPage-1; - if(this.dataStorage.storage.length < lastItem){ + if((this.dataStorage.storage.length - 1) < lastItem){ return this.dataStorage.storage.length - 1; } @@ -688,150 +835,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 627bb8b5449cadb600836481fa7d2327060d8aac Mon Sep 17 00:00:00 2001 From: Ries van Twisk Date: Thu, 16 Feb 2017 20:32:00 +0100 Subject: [PATCH 3/3] Clickable row feature --- README.md | 2 + .../main/directives/mdtTableDirective.js | 10 +++- .../main/features/ClickableRowsFeature.js | 32 ++++++++++++ .../main/templates/rows/generateRows.html | 3 +- dist/md-data-table-templates.js | 2 +- dist/md-data-table.js | 51 ++++++++++++++++--- 6 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 app/modules/main/features/ClickableRowsFeature.js diff --git a/README.md b/README.md index 388cd13..c287e86 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ http://www.google.com/design/spec/components/data-tables.html - virtual-repeat - delete-row-callback - selected-row-callback + - clicked-row-callback - animate-sort-icon - ripple-effect - ! title-overflow-handler @@ -89,6 +90,7 @@ http://www.google.com/design/spec/components/data-tables.html |:white_check_mark:| virtual-repeat | Boolean | optional, when set, virtual scrolling will be applied to the table. You must set a fixed height to the `.md-virtual-repeat-container` class in order to make it work properly. Since virtual scrolling is working with fixed height. | |:white_check_mark:| delete-row-callback | Function | optional, callback function when deleting rows. The callback will be called with the array of the deleted row ids. Don't forget to specify `table-row-id` for `mdt-row`. If you do, it will return the deleted rows data. | |:white_check_mark:| selected-row-callback | Function | optional, callback function when selecting rows. The callback will be called with the array of the selected row ids. Don't forget to specify `table-row-id` for `mdt-row`. If you do, it will return the selected rows data. | +|:white_check_mark:| clicked-row-callback | Function | optional, callback function when clicked rows. The callback will be called when the row is clicked. Don't forget to specify `table-row-id` for `mdt-row`. | ![alt tag](http://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0B3mOPoJlxiFhcWNyQl9xYmRkQnc/components_datatables_interaction_selectedrow.png) | Available | Params | Type | Details | diff --git a/app/modules/main/directives/mdtTableDirective.js b/app/modules/main/directives/mdtTableDirective.js index 64c0857..665c57d 100644 --- a/app/modules/main/directives/mdtTableDirective.js +++ b/app/modules/main/directives/mdtTableDirective.js @@ -116,6 +116,7 @@ function mdtTableDirective(TableDataStorageFactory, EditCellFeature, SelectableRowsFeature, + ClickableRowsFeature, PaginationFeature, ColumnSelectorFeature, _){ @@ -128,7 +129,7 @@ selectableRows: '=', alternateHeaders: '=', deleteRowCallback: '&', - selectedRowCallback: '&', + clickedRowCallback: '&', saveRowCallback: '&', animateSortIcon: '=', rippleEffect: '=', @@ -220,6 +221,7 @@ _initEditCellFeature(); _initSelectableRowsFeature(); + _initClickableRowsFeature(); PaginationFeature.startFeature(ctrl); ColumnSelectorFeature.initFeatureHeaderValues($scope.dataStorage.header, ctrl.columnSelectorFeature); @@ -274,6 +276,12 @@ ctrl: ctrl }); } + function _initClickableRowsFeature(){ + ClickableRowsFeature.getInstance({ + $scope: $scope, + ctrl: ctrl + }); + } } }; } diff --git a/app/modules/main/features/ClickableRowsFeature.js b/app/modules/main/features/ClickableRowsFeature.js new file mode 100644 index 0000000..95780a8 --- /dev/null +++ b/app/modules/main/features/ClickableRowsFeature.js @@ -0,0 +1,32 @@ +(function () { + 'use strict'; + + function ClickableRowsFeatureFactory($timeout) { + + function ClickableRowsFeature(params) { + this.$scope = params.$scope; + this.ctrl = params.ctrl; + + this.$scope.rowClickCallBackHandler = _.bind(this.rowClickCallBackHandler, this); + } + + ClickableRowsFeature.prototype.rowClickCallBackHandler = function (event, row) { + 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.clickedRowCallback({rowId: row.rowId}); + }, 0); + }; + + return { + getInstance: function (params) { + return new ClickableRowsFeature(params); + } + }; + } + + angular + .module('mdDataTable') + .service('ClickableRowsFeature', ClickableRowsFeatureFactory); +}()); \ No newline at end of file diff --git a/app/modules/main/templates/rows/generateRows.html b/app/modules/main/templates/rows/generateRows.html index f194732..50732d8 100644 --- a/app/modules/main/templates/rows/generateRows.html +++ b/app/modules/main/templates/rows/generateRows.html @@ -1,7 +1,8 @@ + ng-show="(isPaginationEnabled() === false || rowData.optionList.visible === true) && rowData.optionList.deleted === false" + ng-click="rowClickCallBackHandler($event, rowData)"> diff --git a/dist/md-data-table-templates.js b/dist/md-data-table-templates.js index 77b70ae..9eead10 100644 --- a/dist/md-data-table-templates.js +++ b/dist/md-data-table-templates.js @@ -16,6 +16,6 @@ $templateCache.put("/main/templates/cells/generateCellValue.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/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 e042197..1d40c47 100644 --- a/dist/md-data-table.js +++ b/dist/md-data-table.js @@ -223,10 +223,11 @@ * * */ - mdtTableDirective.$inject = ['TableDataStorageFactory', 'EditCellFeature', 'SelectableRowsFeature', 'PaginationFeature', 'ColumnSelectorFeature', '_']; + mdtTableDirective.$inject = ['TableDataStorageFactory', 'EditCellFeature', 'SelectableRowsFeature', 'ClickableRowsFeature', 'PaginationFeature', 'ColumnSelectorFeature', '_']; function mdtTableDirective(TableDataStorageFactory, EditCellFeature, SelectableRowsFeature, + ClickableRowsFeature, PaginationFeature, ColumnSelectorFeature, _){ @@ -239,7 +240,7 @@ selectableRows: '=', alternateHeaders: '=', deleteRowCallback: '&', - selectedRowCallback: '&', + clickedRowCallback: '&', saveRowCallback: '&', animateSortIcon: '=', rippleEffect: '=', @@ -331,6 +332,7 @@ _initEditCellFeature(); _initSelectableRowsFeature(); + _initClickableRowsFeature(); PaginationFeature.startFeature(ctrl); ColumnSelectorFeature.initFeatureHeaderValues($scope.dataStorage.header, ctrl.columnSelectorFeature); @@ -385,6 +387,12 @@ ctrl: ctrl }); } + function _initClickableRowsFeature(){ + ClickableRowsFeature.getInstance({ + $scope: $scope, + ctrl: ctrl + }); + } } }; } @@ -620,9 +628,7 @@ }; mdtAjaxPaginationHelper.prototype.getFirstPage = function(){ - this.page = 1; - - this.fetchPage(this.page); + this.fetchPage(1); }; mdtAjaxPaginationHelper.prototype.hasNextPage = function(){ @@ -832,6 +838,39 @@ .module('mdDataTable') .service('mdtPaginationHelperFactory', mdtPaginationHelperFactory); }()); +(function () { + 'use strict'; + + ClickableRowsFeatureFactory.$inject = ['$timeout']; + function ClickableRowsFeatureFactory($timeout) { + + function ClickableRowsFeature(params) { + this.$scope = params.$scope; + this.ctrl = params.ctrl; + + this.$scope.rowClickCallBackHandler = _.bind(this.rowClickCallBackHandler, this); + } + + ClickableRowsFeature.prototype.rowClickCallBackHandler = function (event, row) { + 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.clickedRowCallback({rowId: row.rowId}); + }, 0); + }; + + return { + getInstance: function (params) { + return new ClickableRowsFeature(params); + } + }; + } + + angular + .module('mdDataTable') + .service('ClickableRowsFeature', ClickableRowsFeatureFactory); +}()); (function(){ 'use strict'; @@ -895,7 +934,7 @@ this.$scope = params.$scope; this.ctrl = params.ctrl; - this.$scope.onCheckboxChange = _.bind(this.onCheckboxChange, this); + this.$scope.onRowClicked = _.bind(this.onCheckboxChange, this); } SelectableRowsFeature.prototype.onCheckboxChange = function(){