Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last page mismatch fix #349

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 |
Expand Down
10 changes: 9 additions & 1 deletion app/modules/main/directives/mdtTableDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
function mdtTableDirective(TableDataStorageFactory,
EditCellFeature,
SelectableRowsFeature,
ClickableRowsFeature,
PaginationFeature,
ColumnSelectorFeature,
_){
Expand All @@ -128,7 +129,7 @@
selectableRows: '=',
alternateHeaders: '=',
deleteRowCallback: '&',
selectedRowCallback: '&',
clickedRowCallback: '&',
saveRowCallback: '&',
animateSortIcon: '=',
rippleEffect: '=',
Expand Down Expand Up @@ -220,6 +221,7 @@

_initEditCellFeature();
_initSelectableRowsFeature();
_initClickableRowsFeature();

PaginationFeature.startFeature(ctrl);
ColumnSelectorFeature.initFeatureHeaderValues($scope.dataStorage.header, ctrl.columnSelectorFeature);
Expand Down Expand Up @@ -274,6 +276,12 @@
ctrl: ctrl
});
}
function _initClickableRowsFeature(){
ClickableRowsFeature.getInstance({
$scope: $scope,
ctrl: ctrl
});
}
}
};
}
Expand Down
13 changes: 7 additions & 6 deletions app/modules/main/factories/mdtAjaxPaginationHelperFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -66,7 +66,6 @@
var that = this;
if(this.hasPreviousPage()){
this.fetchPage(this.page-1).then(function(){
that.page--;
});
}
};
Expand All @@ -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(){
Expand All @@ -95,6 +91,11 @@
};

mdtAjaxPaginationHelper.prototype.fetchPage = function(page){
if (page) {
this.page = page;
} else {
page = this.page;
}
this.isLoading = true;

var that = this;
Expand Down
2 changes: 1 addition & 1 deletion app/modules/main/factories/mdtPaginationHelperFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
32 changes: 32 additions & 0 deletions app/modules/main/features/ClickableRowsFeature.js
Original file line number Diff line number Diff line change
@@ -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);
}());
3 changes: 2 additions & 1 deletion app/modules/main/templates/rows/generateRows.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<tr class="tbodyTrRow"
ng-repeat="rowData in mdtPaginationHelper.getRows() track by $index"
ng-class="{'selectedRow': rowData.optionList.selected, '{{rowData.optionList.className}}': rowData.optionList.className }"
ng-show="(isPaginationEnabled() === false || rowData.optionList.visible === true) && rowData.optionList.deleted === false">
ng-show="(isPaginationEnabled() === false || rowData.optionList.visible === true) && rowData.optionList.deleted === false"
ng-click="rowClickCallBackHandler($event, rowData)">

<td class="checkboxCell" ng-show="selectableRows"
ng-include="'/main/templates/cells/generateCheckboxCell.html'"></td>
Expand Down
Loading