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`. |

| 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/factories/mdtAjaxPaginationHelperFactory.js b/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js
index 1bd3a92..051a60b 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;
}
@@ -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/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;
}
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 213a0f7..9eead10 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");
-$templateCache.put("/main/templates/largeEditDialog.html","\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","");
-$templateCache.put("/main/templates/mdtCardFooter.html","");
-$templateCache.put("/main/templates/mdtCardHeader.html","");
-$templateCache.put("/main/templates/mdtCheckboxColumnFilter.html","\r\n
\r\n
\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 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\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\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\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");
-$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");
+$templateCache.put("/main/templates/largeEditDialog.html","\n \n \n \n\n \n {{mdtTranslations.largeEditDialog.saveButtonLabel}}\n {{mdtTranslations.largeEditDialog.cancelButtonLabel}}\n \n\n");
+$templateCache.put("/main/templates/mdtAlternateHeaders.html","");
+$templateCache.put("/main/templates/mdtCardFooter.html","");
+$templateCache.put("/main/templates/mdtCardHeader.html","");
+$templateCache.put("/main/templates/mdtCheckboxColumnFilter.html","\n
\n
\n \n\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\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\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\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");
+$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..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
+ });
+ }
}
};
}
@@ -394,6 +402,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 +596,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 +615,6 @@
var that = this;
if(this.hasPreviousPage()){
this.fetchPage(this.page-1).then(function(){
- that.page--;
});
}
};
@@ -472,15 +623,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(){
@@ -492,6 +640,11 @@
};
mdtAjaxPaginationHelper.prototype.fetchPage = function(page){
+ if (page) {
+ this.page = page;
+ } else {
+ page = this.page;
+ }
this.isLoading = true;
var that = this;
@@ -630,7 +783,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;
}
@@ -685,149 +838,38 @@
.module('mdDataTable')
.service('mdtPaginationHelperFactory', mdtPaginationHelperFactory);
}());
-(function(){
+(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;
- }
+ ClickableRowsFeatureFactory.$inject = ['$timeout'];
+ function ClickableRowsFeatureFactory($timeout) {
- _.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 = [];
+ function ClickableRowsFeature(params) {
+ this.$scope = params.$scope;
+ this.ctrl = params.ctrl;
- _.each(rowData.data, function(aCell){
- rawRowData.push(aCell.value);
- });
+ this.$scope.rowClickCallBackHandler = _.bind(this.rowClickCallBackHandler, this);
+ }
- return rawRowData;
+ 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(){
- return new TableDataStorageService();
+ getInstance: function (params) {
+ return new ClickableRowsFeature(params);
}
};
}
angular
.module('mdDataTable')
- .factory('TableDataStorageFactory', TableDataStorageFactory);
+ .service('ClickableRowsFeature', ClickableRowsFeatureFactory);
}());
(function(){
'use strict';
@@ -892,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(){