.itemsAvailable - (boolean) If 'false', displays the {@link patternfly.views.component:pfEmptyState Empty State} component.
*
.showCheckboxes - (boolean) Show checkboxes for row selection, default is true
*
- * @param {object} dtOptions Optional angular-datatables DTOptionsBuilder configuration object. See {@link http://l-lin.github.io/angular-datatables/archives/#/api angular-datatables: DTOptionsBuilder}
+ * @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.
+ * Please switch to prefered 'pageConfig' settings for pf pagination controls.
+ * Other dtOptions can still be used, such as 'order' See {@link http://l-lin.github.io/angular-datatables/archives/#/api angular-datatables: DTOptionsBuilder}
+ * @param {object} pageConfig Optional pagination configuration object. Since all properties are optional it is ok to specify: 'pageConfig = {}' to indicate that you want to
+ * use pagination with the default parameters.
+ *
+ *
.pageNumber - (number) Optional Initial page number to display. Default is page 1.
+ *
.pageSize - (number) Optional Initial page size/display length to use. Ie. Number of "Items per Page". Default is 10 items per page
+ *
.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]
+ *
* @param {array} items Array of items to display in the table view.
* @param {array} columns Array of table column information to display in the table's header row and optionaly render the cells of a column.
*
@@ -86,24 +95,23 @@
+
-
+
-
@@ -154,28 +161,22 @@
{ header: "BirthMonth", itemField: "birthMonth"}
];
- $scope.dtOptions = {
- paginationType: 'full',
- displayLength: 10,
- dom: "tp"
- };
-
- // [WIP] attempt to dyamically change displayLength (#rows) and turn on/off pagination controls
- // See: issues turning on/off pagination. see: https://datatables.net/manual/tech-notes/3
+ // dtOptions paginationType, displayLength, and dom:"p" are no longer being
+ // used, but are allowed for backward compatibility.
+ // Please switch to prefered 'pageConfig' settings for pf pagination controls
+ // Other dtOptions can still be used, such as 'order'
+ // $scope.dtOptions = {
+ // paginationType: 'full',
+ // displayLength: 10,
+ // dom: "tp"
+ // }
- $scope.usePagination = true;
- $scope.togglePagination = function () {
- $scope.usePagination = !$scope.usePagination;
- console.log("---> togglePagination: " + $scope.usePagination);
- if($scope.usePagination) {
- $scope.dtOptions.displayLength = 3;
- $scope.dtOptions.dom = "tp";
- console.log("---> use pagination: " + $scope.dtOptions.displayLength + ":" + $scope.dtOptions.dom);
- } else {
- $scope.dtOptions.displayLength = undefined;
- $scope.dtOptions.dom = "t";
- }
- };
+ // New pagination config settings
+ $scope.pageConfig = {
+ pageNumber: 1,
+ pageSize: 10,
+ pageSizeIncrements: [5, 10, 15]
+ }
$scope.allItems = [
{
@@ -305,6 +306,8 @@
match = item.address.match(filter.value) !== null;
} else if (filter.id === 'birthMonth') {
match = item.birthMonth === filter.value;
+ } else if (filter.id === 'status') {
+ match = item.status === filter.value;
}
return match;
};
@@ -364,6 +367,13 @@
$scope.filterConfig = {
fields: [
+ {
+ id: 'status',
+ title: 'Status',
+ placeholder: 'Filter by Status...',
+ filterType: 'select',
+ filterValues: ['error', 'warning', 'ok']
+ },
{
id: 'name',
title: 'Name',
diff --git a/src/table/tableview/table-view.component.js b/src/table/tableview/table-view.component.js
index 1a87283f3..d424a6752 100644
--- a/src/table/tableview/table-view.component.js
+++ b/src/table/tableview/table-view.component.js
@@ -7,6 +7,7 @@ angular.module('patternfly.table').component('pfTableView', {
items: '<',
actionButtons: '',
menuActions: '',
+ pageConfig: '=?',
emptyStateConfig: '=?',
emptyStateActionButtons: '=?'
},
@@ -51,8 +52,45 @@ angular.module('patternfly.table').component('pfTableView', {
if (angular.isUndefined(ctrl.dtOptions)) {
ctrl.dtOptions = {};
- } else if (angular.isDefined(ctrl.dtOptions.paginationType)) {
+ } else {
+ // Switch dtOption pagination properties to new pagination schema
+ if (angular.isDefined(ctrl.dtOptions.paginationType)) {
+ ctrl.dtOptions.paging = true;
+ if (angular.isUndefined(ctrl.pageConfig)) {
+ ctrl.pageConfig = {};
+ }
+ if (angular.isUndefined(ctrl.pageConfig.pageNumber)) {
+ ctrl.pageConfig.pageNumber = 1;
+ }
+ }
+ if (angular.isDefined(ctrl.dtOptions.displayLength)) {
+ ctrl.dtOptions.paging = true;
+ if (angular.isUndefined(ctrl.pageConfig)) {
+ ctrl.pageConfig = {};
+ }
+ if (angular.isUndefined(ctrl.pageConfig.pageSize)) {
+ ctrl.pageConfig.pageSize = ctrl.dtOptions.displayLength;
+ }
+ }
+ if (angular.isDefined(ctrl.dtOptions.dom)) {
+ if (ctrl.dtOptions.dom.indexOf("p") !== -1) {
+ // No longer show angular-datatables pagination controls
+ ctrl.dtOptions.dom = ctrl.dtOptions.dom.replace(/p/gi, "");
+ }
+ }
+ }
+
+ // Use new paging schema to set dtOptions paging properties
+ if (angular.isDefined(ctrl.pageConfig)) {
ctrl.dtOptions.paging = true;
+ ctrl.pageConfig.numTotalItems = ctrl.items.length;
+ if (angular.isUndefined(ctrl.pageConfig.pageSize)) {
+ ctrl.pageConfig.pageSize = 10;
+ }
+ ctrl.dtOptions.displayLength = ctrl.pageConfig.pageSize;
+ if (angular.isUndefined(ctrl.pageConfig.pageNumber)) {
+ ctrl.pageConfig.pageNumber = 1;
+ }
}
if (angular.isUndefined(ctrl.config)) {
@@ -130,6 +168,21 @@ angular.module('patternfly.table').component('pfTableView', {
}
};
+ ctrl.updatePageSize = function (event) {
+ ctrl.pageConfig.pageSize = event.pageSize;
+ ctrl.dtOptions.displayLength = ctrl.pageConfig.pageSize;
+ ctrl.pageConfig.pageNumber = 1; // goto first page after pageSize/displayLength change
+ };
+
+ ctrl.updatePageNumber = function (event) {
+ if (ctrl.dtInstance) {
+ ctrl.pageConfig.pageNumber = event.pageNumber;
+ if (ctrl.dtInstance && ctrl.dtInstance.dataTable) {
+ ctrl.dtInstance.dataTable.fnPageChange(ctrl.pageConfig.pageNumber - 1);
+ }
+ }
+ };
+
ctrl.$doCheck = function () {
if (ctrl.debug) {
$log.debug("$doCheck");
@@ -145,10 +198,13 @@ angular.module('patternfly.table').component('pfTableView', {
if (ctrl.debug) {
$log.debug(" items !== prevItems");
}
+ if (ctrl.items) {
+ ctrl.config.itemsAvailable = ctrl.items.length > 0;
+ }
+ if (angular.isDefined(ctrl.pageConfig) && angular.isDefined(ctrl.pageConfig.numTotalItems)) {
+ ctrl.pageConfig.numTotalItems = ctrl.items.length;
+ }
prevItems = angular.copy(ctrl.items);
- //$timeout(function () {
- selectRowsByChecked();
- //});
}
};
@@ -198,9 +254,14 @@ angular.module('patternfly.table').component('pfTableView', {
function listenForDraw () {
var oTable;
var dtInstance = ctrl.dtInstance;
+
if (dtInstance && dtInstance.dataTable) {
oTable = dtInstance.dataTable;
+ if (angular.isDefined(ctrl.pageConfig) && angular.isDefined(ctrl.pageConfig.pageNumber)) {
+ oTable.fnPageChange(ctrl.pageConfig.pageNumber - 1);
+ }
ctrl.tableId = oTable[0].id;
+ oTable.off('draw.dt');
oTable.on('draw.dt', function () {
if (ctrl.debug) {
$log.debug("--> redraw");
@@ -230,6 +291,7 @@ angular.module('patternfly.table').component('pfTableView', {
}
}
});
+ selectRowsByChecked();
};
ctrl.toggleOne = function (item) {
diff --git a/src/table/tableview/table-view.html b/src/table/tableview/table-view.html
index 8a41a34db..1941073e2 100644
--- a/src/table/tableview/table-view.html
+++ b/src/table/tableview/table-view.html
@@ -54,5 +54,11 @@
+
+