This repository has been archived by the owner on Mar 31, 2024. It is now read-only.
forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request elastic#2013 from w33ble/page-table
Paginated table directive
- Loading branch information
Showing
8 changed files
with
352 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,13 @@ | ||
<paginate | ||
<paginated-table | ||
ng-if="formattedRows.length" | ||
|
||
list="formattedRows" | ||
per-page-prop="perPage" | ||
|
||
class="agg-table"> | ||
<div class="agg-table-paginated"> | ||
<table class="table table-condensed"> | ||
<thead> | ||
<tr bindonce> | ||
<th | ||
ng-repeat="col in table.columns" | ||
ng-click="aggTable.cycleSort(col)" | ||
ng-class="aggTable.getColumnClass(col, $first, $last)"> | ||
<span bo-text="col.title"></span> | ||
<i | ||
class="fa" | ||
ng-class="{ | ||
'fa-sort-asc': aggTable.sort.col === col && aggTable.sort.asc, | ||
'fa-sort-desc': aggTable.sort.col === col && !aggTable.sort.asc, | ||
'fa-sort': !aggTable.sort || aggTable.sort.col !== col | ||
}"> | ||
</i> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody kbn-rows="page" kbn-rows-min="perPage"></tbody> | ||
</table> | ||
</div> | ||
rows="formattedRows" | ||
columns="formattedColumns" | ||
per-page="perPage"> | ||
|
||
<div class="agg-table-controls"> | ||
<a class="small" ng-click="aggTable.exportAsCsv()"> | ||
Export <i class="fa fa-download"></i> | ||
</a> | ||
<paginate-controls></paginate-controls> | ||
</div> | ||
</paginate> | ||
</paginated-table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/kibana/components/paginated_table/paginated_table.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<paginate | ||
ng-if="sortedRows.length" | ||
list="sortedRows" | ||
per-page-prop="perPage" | ||
class="agg-table"> | ||
<div class="agg-table-paginated"> | ||
<table class="table table-condensed"> | ||
<thead> | ||
<tr bindonce> | ||
<th | ||
ng-repeat="col in columns" | ||
ng-click="paginatedTable.sortColumn(col)" | ||
class="{{ col.class }}"> | ||
<span bo-text="col.title"></span> | ||
<i | ||
class="fa" | ||
ng-class="{ | ||
'fa-sort-asc': paginatedTable.sort.columnName === col.title && paginatedTable.sort.direction === 'asc', | ||
'fa-sort-desc': paginatedTable.sort.columnName === col.title && paginatedTable.sort.direction === 'desc', | ||
'fa-sort': paginatedTable.sort.direction === null || paginatedTable.sort.columnName !== col.title | ||
}"> | ||
</i> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody kbn-rows="page" kbn-rows-min="perPage"></tbody> | ||
</table> | ||
</div> | ||
|
||
<!-- auto-inserted by the paginate directive... --> | ||
<!-- <paginate-controls></paginate-controls> --> | ||
<div class="pagination-container" ng-transclude></div> | ||
|
||
</paginate> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
define(function (require) { | ||
require('modules') | ||
.get('kibana') | ||
.directive('paginatedTable', function ($filter, config, Private) { | ||
var _ = require('lodash'); | ||
var orderBy = $filter('orderBy'); | ||
|
||
return { | ||
restrict: 'E', | ||
template: require('text!components/paginated_table/paginated_table.html'), | ||
transclude: true, | ||
scope: { | ||
rows: '=', | ||
columns: '=', | ||
perPage: '=?', | ||
sortHandler: '=?', | ||
showSelector: '=?' | ||
}, | ||
controllerAs: 'paginatedTable', | ||
controller: function ($scope) { | ||
var self = this; | ||
self.sort = { | ||
columnName: null, | ||
direction: null | ||
}; | ||
|
||
self.sortColumn = function (col) { | ||
var sortDirection; | ||
var cols = _.pluck($scope.columns, 'title'); | ||
var index = cols.indexOf(col.title); | ||
|
||
if (index === -1) return; | ||
|
||
if (self.sort.columnName !== col.title) { | ||
sortDirection = 'asc'; | ||
} else { | ||
var directions = { | ||
null: 'asc', | ||
'asc': 'desc', | ||
'desc': null | ||
}; | ||
sortDirection = directions[self.sort.direction]; | ||
} | ||
|
||
self.sort.columnName = col.title; | ||
self.sort.direction = sortDirection; | ||
self._setSortGetter(index); | ||
}; | ||
|
||
self._setSortGetter = function (index) { | ||
if (_.isFunction($scope.sortHandler)) { | ||
// use custom sort handler | ||
self.sort.getter = $scope.sortHandler(index); | ||
} else { | ||
// use generic sort handler | ||
self.sort.getter = function (row) { | ||
return row[index]; | ||
}; | ||
} | ||
}; | ||
|
||
// update the sordedRows result | ||
$scope.$watchMulti([ | ||
'paginatedTable.sort.direction', | ||
'rows' | ||
], function () { | ||
if (self.sort.direction == null) { | ||
$scope.sortedRows = $scope.rows.slice(0); | ||
return; | ||
} | ||
|
||
$scope.sortedRows = orderBy($scope.rows, self.sort.getter, self.sort.direction === 'desc'); | ||
}); | ||
} | ||
}; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.