Skip to content

Commit 0ea5acb

Browse files
dtaylor113cdcabrera
authored andcommitted
pfTableView with pfPagination (#527)
* pfTableView with pfPagination * Addressed Review Issues
1 parent 29fdf26 commit 0ea5acb

15 files changed

+297
-78
lines changed

Gruntfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ module.exports = function (grunt) {
179179
'node_modules/patternfly/dist/js/patternfly-settings-charts.js',
180180
'node_modules/angular/angular.js',
181181
'node_modules/angular-dragdrop/src/angular-dragdrop.js',
182-
'node_modules/angular-datatables/dist/angular-datatables.min.js',
183-
'node_modules/angular-datatables/dist/plugins/select/angular-datatables.select.min.js',
182+
'node_modules/angularjs-datatables/dist/angular-datatables.js',
183+
'node_modules/angularjs-datatables/dist/plugins/select/angular-datatables.select.min.js',
184184
'node_modules/angular-sanitize/angular-sanitize.js',
185185
'node_modules/angular-animate/angular-animate.js',
186186
'node_modules/angular-ui-bootstrap/dist/ui-bootstrap-tpls.js',

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ Note:
120120
<script src="node_modules/jquery/dist/jquery.js"></script>
121121
<script src="node_modules/datatables.net/js/jquery.dataTables.js"></script>
122122
<script src="node_modules/datatables.net-select/js/dataTables.select.js"></script>
123-
<script src="node_modules/angular-datatables/dist/angular-datatables.min.js"></script>
124-
<script src="node_modules/angular-datatables/dist/plugins/select/angular-datatables.select.min.js"></script>
123+
<script src="node_modules/angularjs-datatables/dist/angular-datatables.min.js"></script>
124+
<script src="node_modules/angularjs-datatables/dist/plugins/select/angular-datatables.select.min.js"></script>
125125
```
126126
7. (optional) The 'patternfly.canvas' module is not a dependency in the default angular 'patternfly' module.
127127
In order to use pfCanvasEditor or pfCanvas, you must add 'patternfly.canvas' as a dependency in your application:

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"angular-animate": "1.5.*",
4242
"angular-bootstrap": "2.2.x",
4343
"angular-dragdrop": "1.0.13",
44-
"angular-datatables": "^0.5.6",
44+
"angularjs-datatables": "^0.5.7",
4545
"angular-drag-and-drop-lists": "2.0.0",
4646
"angular-sanitize": "1.5.*",
4747
"datatables.net": "^1.10.12",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"patternfly-eng-release": "3.24.3"
5757
},
5858
"optionalDependencies": {
59-
"angular-datatables": "^0.5.6",
59+
"angularjs-datatables": "^0.5.7",
6060
"angular-drag-and-drop-lists": "2.0.0",
6161
"bootstrap-select": "~1.10.0",
6262
"c3": "~0.4.11",

src/pagination/pagination.component.js

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</div>
3535
</div>
3636
<pf-pagination
37-
page-size="pageSize",
37+
page-size="pageSize"
3838
page-number="pageNumber"
3939
num-total-items="numTotalItems">
4040
</pf-pagination>
@@ -59,10 +59,12 @@ angular.module('patternfly.pagination').component('pfPagination', {
5959
transclude: true,
6060
templateUrl: 'pagination/pagination.html',
6161
bindings: {
62-
pageNumber: '=',
62+
pageNumber: '=?',
6363
numTotalItems: "<",
6464
pageSizeIncrements: '<?',
65-
pageSize: "=?"
65+
pageSize: "=?",
66+
updatePageSize: "&",
67+
updatePageNumber: "&"
6668
},
6769
controller: function ($scope, $log) {
6870
'use strict';
@@ -71,6 +73,9 @@ angular.module('patternfly.pagination').component('pfPagination', {
7173
var defaultPageSizeIncrements = [5, 10, 20, 40, 80, 100];
7274

7375
ctrl.$onInit = function () {
76+
if (angular.isUndefined(ctrl.pageNumber)) {
77+
ctrl.pageNumber = 1;
78+
}
7479
if (angular.isUndefined(ctrl.pageSizeIncrements)) {
7580
ctrl.pageSizeIncrements = defaultPageSizeIncrements;
7681
}
@@ -83,59 +88,80 @@ angular.module('patternfly.pagination').component('pfPagination', {
8388
ctrl.$onChanges = function (changesObj) {
8489
if (changesObj.numTotalItems && !changesObj.numTotalItems.isFirstChange()) {
8590
ctrl.lastPageNumber = getLastPageNumber();
91+
ctrl.gotoFirstPage();
8692
}
8793
};
8894

8995
ctrl.onPageSizeChange = function (newPageSize) {
9096
ctrl.pageSize = newPageSize;
9197
ctrl.lastPageNumber = getLastPageNumber();
9298
ctrl.gotoFirstPage();
99+
if (ctrl.updatePageSize) {
100+
ctrl.updatePageSize({
101+
$event: {
102+
pageSize: newPageSize
103+
}
104+
});
105+
}
93106
};
94107

95108
ctrl.onPageNumberChange = function () {
96-
ctrl.pageNumber = parseInt(ctrl.pageNumber, 10);
97-
if (ctrl.pageNumber > ctrl.lastPageNumber) {
98-
ctrl.pageNumber = ctrl.lastPageNumber;
99-
} else if (ctrl.pageNumber < 1 || isNaN(ctrl.pageNumber)) {
100-
ctrl.pageNumber = 1;
109+
var newPageNumber = parseInt(ctrl.pageNumber, 10);
110+
if (newPageNumber > ctrl.lastPageNumber) {
111+
updatePageNumber(ctrl.lastPageNumber);
112+
} else if (newPageNumber < 1 || isNaN(ctrl.pageNumber)) {
113+
updatePageNumber(1);
114+
} else {
115+
updatePageNumber(newPageNumber);
101116
}
102117
};
103118

104119
ctrl.gotoFirstPage = function () {
105120
if (ctrl.pageNumber !== 1) {
106-
ctrl.pageNumber = 1;
121+
updatePageNumber(1);
107122
}
108123
};
109124

110125
ctrl.gotoPreviousPage = function () {
111126
if (ctrl.pageNumber !== 1) {
112-
ctrl.pageNumber--;
127+
updatePageNumber(ctrl.pageNumber - 1);
113128
}
114129
};
115130

116131
ctrl.gotoNextPage = function () {
117132
if (ctrl.pageNumber < ctrl.lastPageNumber) {
118-
ctrl.pageNumber++;
133+
updatePageNumber(ctrl.pageNumber + 1);
119134
}
120135
};
121136

122137
ctrl.gotoLastPage = function () {
123138
if (ctrl.pageNumber < ctrl.lastPageNumber) {
124-
ctrl.pageNumber = ctrl.lastPageNumber;
139+
updatePageNumber(ctrl.lastPageNumber);
125140
}
126141
};
127142

128143
ctrl.getStartIndex = function () {
129-
return ctrl.pageSize * (ctrl.pageNumber - 1) + 1;
144+
return ctrl.numTotalItems ? ctrl.pageSize * (ctrl.pageNumber - 1) + 1 : 0;
130145
};
131146

132147
ctrl.getEndIndex = function () {
133148
var numFullPages = Math.floor(ctrl.numTotalItems / ctrl.pageSize);
134-
var numItemsOnLastPage = ctrl.numTotalItems - (numFullPages * ctrl.pageSize);
149+
var numItemsOnLastPage = ctrl.numTotalItems - (numFullPages * ctrl.pageSize) || ctrl.pageSize;
135150
var numItemsOnPage = isLastPage() ? numItemsOnLastPage : ctrl.pageSize;
136-
return ctrl.getStartIndex() + numItemsOnPage - 1;
151+
return ctrl.numTotalItems ? ctrl.getStartIndex() + numItemsOnPage - 1 : 0;
137152
};
138153

154+
function updatePageNumber (newPageNumber) {
155+
ctrl.pageNumber = newPageNumber;
156+
if (ctrl.updatePageNumber) {
157+
ctrl.updatePageNumber({
158+
$event: {
159+
pageNumber: ctrl.pageNumber
160+
}
161+
});
162+
}
163+
}
164+
139165
function getLastPageNumber () {
140166
return Math.ceil(ctrl.numTotalItems / ctrl.pageSize);
141167
}

src/table/table.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ table.dataTable {
2727
}
2828
}
2929
tbody {
30+
tr.selected {
31+
span a {
32+
color: @color-pf-white;
33+
}
34+
}
3035
th {
3136
padding: 2px 10px 3px;
3237
}

src/table/table.module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
* Table module for patternfly.
66
*
77
*/
8-
angular.module('patternfly.table', ['datatables', 'patternfly.utils', 'patternfly.filters', 'patternfly.sort']);
8+
angular.module('patternfly.table', ['datatables', 'patternfly.pagination', 'patternfly.utils', 'patternfly.filters', 'patternfly.sort']);

src/table/tableview/examples/table-view-basic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
empty-state-action-buttons="emptyStateActionButtons">
6262
</pf-table-view>
6363
</div>
64+
<hr class="col-md-12">
6465
<div class="col-md-12" style="padding-top: 12px;">
6566
<div class="form-group">
6667
<label class="checkbox-inline">
@@ -73,7 +74,6 @@
7374
</label>
7475
</div>
7576
</div>
76-
<hr class="col-md-12">
7777
<div class="col-md-12">
7878
<div class="col-md-12" style="padding-top: 12px;">
7979
<label style="font-weight:normal;vertical-align:center;">Events: </label>
@@ -298,14 +298,14 @@
298298
state: "New York"
299299
},
300300
{
301-
status: "ok",
301+
status: "warning",
302302
name: "Mike Bird",
303303
address: "50 Forth Street",
304304
city: "New York",
305305
state: "New York"
306306
},
307307
{
308-
status: "ok",
308+
status: "error",
309309
name: "Cheryl Taylor",
310310
address: "2 Main Street",
311311
city: "New York",

src/table/tableview/examples/table-view-with-toolbar.js

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@
1313
* <li>.itemsAvailable - (boolean) If 'false', displays the {@link patternfly.views.component:pfEmptyState Empty State} component.
1414
* <li>.showCheckboxes - (boolean) Show checkboxes for row selection, default is true
1515
* </ul>
16-
* @param {object} dtOptions Optional angular-datatables DTOptionsBuilder configuration object. See {@link http://l-lin.github.io/angular-datatables/archives/#/api angular-datatables: DTOptionsBuilder}
16+
* @param {object} dtOptions Optional angular-datatables DTOptionsBuilder configuration object. Note: paginationType, displayLength, and dom:"p" are no longer being used for pagination, but are allowed for backward compatibility.
17+
* Please switch to prefered 'pageConfig' settings for pf pagination controls.
18+
* Other dtOptions can still be used, such as 'order' See {@link http://l-lin.github.io/angular-datatables/archives/#/api angular-datatables: DTOptionsBuilder}
19+
* @param {object} pageConfig Optional pagination configuration object. Since all properties are optional it is ok to specify: 'pageConfig = {}' to indicate that you want to
20+
* use pagination with the default parameters.
21+
* <ul style='list-style-type: none'>
22+
* <li>.pageNumber - (number) Optional Initial page number to display. Default is page 1.
23+
* <li>.pageSize - (number) Optional Initial page size/display length to use. Ie. Number of "Items per Page". Default is 10 items per page
24+
* <li>.pageSizeIncrements - (Array[Number]) Optional Page size increments for the 'per page' dropdown. If not specified, the default values are: [5, 10, 20, 40, 80, 100]
25+
* </ul>
1726
* @param {array} items Array of items to display in the table view.
1827
* @param {array} columns Array of table column information to display in the table's header row and optionaly render the cells of a column.
1928
* <ul style='list-style-type: none'>
@@ -86,32 +95,30 @@
8695
<pf-table-view config="tableConfig"
8796
empty-state-config="emptyStateConfig"
8897
dt-options="dtOptions"
98+
page-config="pageConfig"
8999
columns="columns"
90100
items="items"
91101
action-buttons="tableActionButtons"
92102
menu-actions="tableMenuActions">
93103
</pf-table-view>
94104
</div>
105+
<hr class="col-md-12">
95106
<div class="col-md-12">
96107
<div class="form-group">
97108
<label class="checkbox-inline">
98109
<input type="checkbox" ng-model="tableConfig.itemsAvailable" ng-change="updateItemsAvailable()">Items Available</input>
99110
</label>
100-
<!-- //[WIP] issues dynamically changing displayLength and turning on/off pagination
101-
<label class="checkbox-inline">
102-
<input type="checkbox" ng-model="usePagination" ng-change="togglePagination()">Use Pagination</input>
103-
</label>
104-
<label>
105-
<input ng-model="dtOptions.displayLength" ng-disabled="!usePagination" style="width: 24px; padding-left: 6px;"> # Rows Per Page</input>
106-
</label> --!>
111+
<!-- TODO: I don't know why this comment is neccesary, but if I remove it I get error:
112+
Error: [$compile:ctreq] Controller 'tabbable', required by directive 'tabPane', can't be found!
113+
I've wasted too much time trying to fix this! Something to do with ngDoc's <file> directives
114+
--!>
107115
</div>
108116
<div class="form-group">
109117
<label class="checkbox-inline">
110118
<input type="checkbox" ng-model="tableConfig.showCheckboxes" ng-change="addNewComponentToDOM()">Show Checkboxes</input>
111119
</label>
112120
</div>
113121
</div>
114-
<hr class="col-md-12">
115122
<div class="col-md-12">
116123
<label class="actions-label">Actions: </label>
117124
</div>
@@ -154,28 +161,22 @@
154161
{ header: "BirthMonth", itemField: "birthMonth"}
155162
];
156163
157-
$scope.dtOptions = {
158-
paginationType: 'full',
159-
displayLength: 10,
160-
dom: "tp"
161-
};
162-
163-
// [WIP] attempt to dyamically change displayLength (#rows) and turn on/off pagination controls
164-
// See: issues turning on/off pagination. see: https://datatables.net/manual/tech-notes/3
164+
// dtOptions paginationType, displayLength, and dom:"p" are no longer being
165+
// used, but are allowed for backward compatibility.
166+
// Please switch to prefered 'pageConfig' settings for pf pagination controls
167+
// Other dtOptions can still be used, such as 'order'
168+
// $scope.dtOptions = {
169+
// paginationType: 'full',
170+
// displayLength: 10,
171+
// dom: "tp"
172+
// }
165173
166-
$scope.usePagination = true;
167-
$scope.togglePagination = function () {
168-
$scope.usePagination = !$scope.usePagination;
169-
console.log("---> togglePagination: " + $scope.usePagination);
170-
if($scope.usePagination) {
171-
$scope.dtOptions.displayLength = 3;
172-
$scope.dtOptions.dom = "tp";
173-
console.log("---> use pagination: " + $scope.dtOptions.displayLength + ":" + $scope.dtOptions.dom);
174-
} else {
175-
$scope.dtOptions.displayLength = undefined;
176-
$scope.dtOptions.dom = "t";
177-
}
178-
};
174+
// New pagination config settings
175+
$scope.pageConfig = {
176+
pageNumber: 1,
177+
pageSize: 10,
178+
pageSizeIncrements: [5, 10, 15]
179+
}
179180
180181
$scope.allItems = [
181182
{
@@ -305,6 +306,8 @@
305306
match = item.address.match(filter.value) !== null;
306307
} else if (filter.id === 'birthMonth') {
307308
match = item.birthMonth === filter.value;
309+
} else if (filter.id === 'status') {
310+
match = item.status === filter.value;
308311
}
309312
return match;
310313
};
@@ -364,6 +367,13 @@
364367
365368
$scope.filterConfig = {
366369
fields: [
370+
{
371+
id: 'status',
372+
title: 'Status',
373+
placeholder: 'Filter by Status...',
374+
filterType: 'select',
375+
filterValues: ['error', 'warning', 'ok']
376+
},
367377
{
368378
id: 'name',
369379
title: 'Name',

0 commit comments

Comments
 (0)