Skip to content

Commit 1613bb3

Browse files
authored
Merge pull request #1 from CodeFunta/feature-row-click
Feature row click
2 parents 85f0902 + 0d60a44 commit 1613bb3

File tree

12 files changed

+219
-124
lines changed

12 files changed

+219
-124
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ http://www.google.com/design/spec/components/data-tables.html
4242
- virtual-repeat
4343
- delete-row-callback
4444
- selected-row-callback
45+
- clicked-row-callback
4546
- animate-sort-icon
4647
- ripple-effect
4748
- ! title-overflow-handler
@@ -89,6 +90,7 @@ http://www.google.com/design/spec/components/data-tables.html
8990
|: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. |
9091
|: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. |
9192
|: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. |
93+
|: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`. |
9294
![alt tag](http://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0B3mOPoJlxiFhcWNyQl9xYmRkQnc/components_datatables_interaction_selectedrow.png)
9395

9496
| Available | Params | Type | Details |
@@ -358,4 +360,4 @@ There is only one scope variable that you can use in your template, and it's cal
358360
</mdt-row>
359361

360362
</mdt-table>
361-
```
363+
```

app/modules/main/directives/mdtTableDirective.js

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function(){
1+
(function () {
22
'use strict';
33

44
/**
@@ -116,9 +116,10 @@
116116
function mdtTableDirective(TableDataStorageFactory,
117117
EditCellFeature,
118118
SelectableRowsFeature,
119+
ClickableRowsFeature,
119120
PaginationFeature,
120121
ColumnSelectorFeature,
121-
_){
122+
_) {
122123
return {
123124
restrict: 'E',
124125
templateUrl: '/main/templates/mdtTable.html',
@@ -128,24 +129,24 @@
128129
selectableRows: '=',
129130
alternateHeaders: '=',
130131
deleteRowCallback: '&',
131-
selectedRowCallback: '&',
132+
clickedRowCallback: '&',
132133
saveRowCallback: '&',
133134
animateSortIcon: '=',
134135
rippleEffect: '=',
135136
paginatedRows: '=',
136137
mdtRow: '=',
137138
mdtRowPaginator: '&?',
138-
mdtRowPaginatorErrorMessage:'@',
139-
mdtRowPaginatorNoResultsMessage:'@',
139+
mdtRowPaginatorErrorMessage: '@',
140+
mdtRowPaginatorNoResultsMessage: '@',
140141
virtualRepeat: '=',
141142
mdtTriggerRequest: '&?',
142143
mdtTranslations: '=?',
143144
mdtLoadingIndicator: '=?'
144145
},
145-
controller: function mdtTable($scope){
146+
controller: function mdtTable($scope) {
146147
var vm = this;
147148

148-
$scope.rippleEffectCallback = function(){
149+
$scope.rippleEffectCallback = function () {
149150
return $scope.rippleEffect ? $scope.rippleEffect : false;
150151
};
151152

@@ -158,12 +159,12 @@
158159
_processData();
159160

160161
// initialization of the storage service
161-
function _initTableStorage(){
162+
function _initTableStorage() {
162163
vm.dataStorage = TableDataStorageFactory.getInstance();
163164
}
164165

165166
// set translations or fallback to a default value
166-
function _setDefaultTranslations(){
167+
function _setDefaultTranslations() {
167168
$scope.mdtTranslations = $scope.mdtTranslations || {};
168169

169170
$scope.mdtTranslations.rowsPerPage = $scope.mdtTranslations.rowsPerPage || 'Rows per page:';
@@ -174,8 +175,8 @@
174175
}
175176

176177
// fill storage with values if set
177-
function _processData(){
178-
if(_.isEmpty($scope.mdtRow)) {
178+
function _processData() {
179+
if (_.isEmpty($scope.mdtRow)) {
179180
return;
180181
}
181182

@@ -186,19 +187,19 @@
186187

187188
_addRawDataToStorage(mdtRow['data']);
188189
}, true);
189-
}else{
190+
} else {
190191
//if it's used for 'Ajax pagination'
191192
}
192193
}
193194

194-
function _addRawDataToStorage(data){
195+
function _addRawDataToStorage(data) {
195196
var rowId;
196197
var columnValues = [];
197-
_.each(data, function(row){
198+
_.each(data, function (row) {
198199
rowId = _.get(row, $scope.mdtRow['table-row-id-key']);
199200
columnValues = [];
200201

201-
_.each($scope.mdtRow['column-keys'], function(columnKey){
202+
_.each($scope.mdtRow['column-keys'], function (columnKey) {
202203
columnValues.push({
203204
attributes: {
204205
editableField: false
@@ -213,18 +214,19 @@
213214
});
214215
}
215216
},
216-
link: function($scope, element, attrs, ctrl, transclude){
217+
link: function ($scope, element, attrs, ctrl, transclude) {
217218
$scope.dataStorage = ctrl.dataStorage;
218219

219220
_injectContentIntoTemplate();
220221

221222
_initEditCellFeature();
222223
_initSelectableRowsFeature();
224+
_initClickableRowsFeature();
223225

224226
PaginationFeature.startFeature(ctrl);
225227
ColumnSelectorFeature.initFeatureHeaderValues($scope.dataStorage.header, ctrl.columnSelectorFeature);
226228

227-
function _injectContentIntoTemplate(){
229+
function _injectContentIntoTemplate() {
228230
transclude(function (clone) {
229231
var headings = [];
230232
var body = [];
@@ -233,11 +235,11 @@
233235
// Use plain JS to append content
234236
_.each(clone, function (child) {
235237

236-
if ( child.classList !== undefined ) {
237-
if ( child.classList.contains('theadTrRow')) {
238+
if (child.classList !== undefined) {
239+
if (child.classList.contains('theadTrRow')) {
238240
headings.push(child);
239241
}
240-
else if( child.classList.contains('customCell') ) {
242+
else if (child.classList.contains('customCell')) {
241243
customCell.push(child);
242244
}
243245
else {
@@ -251,34 +253,40 @@
251253
var reader = element[0].querySelector('.mdtTable-reader');
252254

253255
_.each(headings, function (heading) {
254-
reader.appendChild( heading );
256+
reader.appendChild(heading);
255257
});
256258

257259
_.each(body, function (item) {
258-
reader.appendChild( item );
260+
reader.appendChild(item);
259261
});
260262
});
261263
}
262264

263-
function _initEditCellFeature(){
265+
function _initEditCellFeature() {
264266
//TODO: make it possible to only register feature if there is at least
265267
// one column which requires it.
266268
// for that we need to change the place where we register edit-row.
267269
// Remove mdt-row attributes --> do it in mdt-row attribute directive on mdtTable
268270
EditCellFeature.addRequiredFunctions($scope, ctrl);
269271
}
270272

271-
function _initSelectableRowsFeature(){
273+
function _initSelectableRowsFeature() {
272274
SelectableRowsFeature.getInstance({
273275
$scope: $scope,
274276
ctrl: ctrl
275277
});
276278
}
279+
function _initClickableRowsFeature() {
280+
ClickableRowsFeature.getInstance({
281+
$scope: $scope,
282+
ctrl: ctrl
283+
});
284+
}
277285
}
278286
};
279287
}
280288

281289
angular
282290
.module('mdDataTable')
283291
.directive('mdtTable', mdtTableDirective);
284-
}());
292+
}());
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(function () {
2+
'use strict';
3+
4+
function ClickableRowsFeatureFactory($timeout) {
5+
6+
function ClickableRowsFeature(params) {
7+
this.$scope = params.$scope;
8+
this.ctrl = params.ctrl;
9+
10+
this.$scope.rowClickCallBackHandler = _.bind(this.rowClickCallBackHandler, this);
11+
}
12+
13+
ClickableRowsFeature.prototype.rowClickCallBackHandler = function (event, row) {
14+
var that = this;
15+
// we need to push it to the event loop to make it happen last
16+
// (e.g.: all the elements can be selected before we call the callback)
17+
$timeout(function () {
18+
that.$scope.clickedRowCallback({ rowId: row.rowId });
19+
}, 0);
20+
};
21+
22+
return {
23+
getInstance: function (params) {
24+
return new ClickableRowsFeature(params);
25+
}
26+
};
27+
}
28+
29+
angular
30+
.module('mdDataTable')
31+
.service('ClickableRowsFeature', ClickableRowsFeatureFactory);
32+
}());

app/modules/main/templates/rows/generateRows.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<tr class="tbodyTrRow"
22
ng-repeat="rowData in mdtPaginationHelper.getRows() track by $index"
33
ng-class="{'selectedRow': rowData.optionList.selected, '{{rowData.optionList.className}}': rowData.optionList.className }"
4-
ng-show="(isPaginationEnabled() === false || rowData.optionList.visible === true) && rowData.optionList.deleted === false">
4+
ng-show="(isPaginationEnabled() === false || rowData.optionList.visible === true) && rowData.optionList.deleted === false"
5+
ng-click="rowClickCallBackHandler($event, rowData)">
56

67
<td class="checkboxCell" ng-show="selectableRows"
78
ng-include="'/main/templates/cells/generateCheckboxCell.html'"></td>
@@ -20,4 +21,4 @@
2021
ng-include src="'/main/templates/rows/errorIndicator.html'"></tr>
2122

2223
<tr ng-show="mdtPaginationHelper.isNoResults && !mdtPaginationHelper.isLoadError"
23-
ng-include src="'/main/templates/rows/noResultIndicator.html'"></tr>
24+
ng-include src="'/main/templates/rows/noResultIndicator.html'"></tr>

bower.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@
2828
],
2929
"dependencies": {
3030
"jquery": "~2.1.4",
31-
"lodash": "~3.10.1",
32-
"angular": "~1.5.8",
33-
"angular-sanitize": "~1.5.8",
34-
"angular-animate": "~1.5.8",
35-
"angular-material": "1.1.1",
36-
"angular-material-icons": "~v0.6.0"
31+
"lodash": "~4.17.4",
32+
"angular": "~1.6.4",
33+
"angular-sanitize": "~1.6.4",
34+
"angular-animate": "~1.6.4",
35+
"angular-material": "1.1.4",
36+
"angular-material-icons": "~0.7.1"
3737
},
3838
"devDependencies": {
39-
"angular-mocks": "~1.5.8"
39+
"angular-mocks": "~1.6.4"
4040
},
4141
"resolutions": {
42-
"angular": "~1.5.8"
42+
"angular": "~1.6.4"
4343
}
4444
}

dist/md-data-table-templates.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)