Skip to content

Commit afd61b7

Browse files
Merge pull request #113 from MyPureCloud/external-filters
External filters
2 parents 6b3ac70 + a80e6af commit afd61b7

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ When invoked, `filterFunction` will be passed a data row and the current filter
480480
481481
Columns that have a custom cell component can be filtered, but only if the data rows defined in `content` have values corresponding to the column using the custom cell component. The filtering will be based on the data in `content`, not on what's rendered by the custom cell component.
482482
483+
483484
### Sorting
484485
485486
Fixtable has built-in support for column sorting.
@@ -556,14 +557,25 @@ Currently, you can only sort by a single column at a time. (In other words, ther
556557
557558
Also, just like with filtering, sorting is based on what's defined in `content`, not on the actual markup rendered in the cell. Keep this in mind when using sorting with custom cell components.
558559
560+
### External Filters
561+
562+
You may want to implement UI for filtering data outside of Fixtable itself. Perhaps in a sibling component that allows for more complex controls than can comfortably fit in a column header.
563+
564+
To support this use case, Fixtable allows for an `externalFilters` property to be set. It will then monitor this value for changes and trigger your `onReloadContent` callback to refresh the table content. The current value of `externalFilters` will be passed to your callback as the fifth parameter.
565+
566+
Fixtable does not prescribe any particular format for your external filters, so you are free to implement whatever data structure works best for your needs. This, however, means you may need to use `notifyPropertyChange()` when your external filters are updated, to explicitly notify Fixtable of the change.
567+
568+
Note: `serverPaging` must be enabled.
569+
559570
### onReloadContent
560571
561-
Let's recap `onReloadContent`, since it can be triggered by several different kinds of content updates. This property of the `fixtable-grid` should be set to an action on the owning controller or component. The bound action will be called whenever the table is paged, sorted, or filtered. (This is true regardless of whether client paging or server paging is active, but obviously it's more important for server paging.) The action will be invoked with the following parameters:
572+
Let's recap `onReloadContent`, since it can be triggered by several different kinds of content updates. This property of the `fixtable-grid` should be set to an action on the owning controller or component. The bound action will be called whenever the table is paged, sorted, or filtered, or when any external filters are changed. (This is true regardless of whether client paging or server paging is active, but obviously it's more important for server paging.) The action will be invoked with the following parameters:
562573
563574
* `page` (Number) - The current 1-indexed page number.
564575
* `pageSize` (Number) - The maximum number of rows shown on a single page.
565576
* `filters` (Object) - Object where the key/value pairs map column keys to filter text.
566577
* `sortInfo` (Object) - Object with a string `key` property representing the column to sort by, and a boolean `ascending` property indicating the sort direction. If the table is unsorted, `sortInfo` will be null.
578+
* `externalFilters` (Object) - The current value of your `externalFilters` property; this is completely outside of Fixtable's control.
567579
568580
### Row Selection
569581

addon/components/fixtable-grid.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import DS from 'ember-data';
44
import Ember from 'ember';
5+
import _ from 'lodash';
56
import layout from '../templates/components/fixtable-grid';
67

78
const checkboxColumnWidth = 40; // in pixels
@@ -41,6 +42,8 @@ export default Ember.Component.extend({
4142
selectedRowMap: null, // maps row indices to selected state
4243
suppressSelectToggle: false,
4344

45+
externalFilters: null,
46+
4447
currentPage: defaultPage,
4548
afterCurrentPageChanged: Ember.observer('currentPage', function fixtableGrid$afterCurrentPageChanged() {
4649
let currentPage = this.get('currentPage'),
@@ -72,7 +75,8 @@ export default Ember.Component.extend({
7275
this.get('currentPage'),
7376
this.get('pageSize'),
7477
this.get('filterToApply') || {},
75-
sortInfo);
78+
sortInfo,
79+
this.get('externalFilters'));
7680
}
7781

7882
// if we need to reload content, that also means the selection will be reset
@@ -462,5 +466,18 @@ export default Ember.Component.extend({
462466
if (fixtable) {
463467
fixtable.setDimensions();
464468
}
469+
},
470+
471+
didUpdateAttrs() {
472+
this._super(...arguments);
473+
474+
// trigger content reload when externalFilters change
475+
let oldExternalFilters = this.get('_previousExternalFilters');
476+
let newExternalFilters = _.cloneDeep(this.get('externalFilters'));
477+
if (oldExternalFilters && !_.isEqual(oldExternalFilters, newExternalFilters)) {
478+
this.set('currentPage', 1);
479+
Ember.run.debounce(this, this.notifyReloadContent, 300, false);
480+
}
481+
this.set('_previousExternalFilters', newExternalFilters);
465482
}
466483
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fixtable-ember",
3-
"version": "3.2.3",
3+
"version": "3.3.0",
44
"description": "Ember wrapper for the Fixtable table library",
55
"directories": {
66
"doc": "doc",
@@ -42,6 +42,7 @@
4242
"ember-disable-prototype-extensions": "^1.1.0",
4343
"ember-export-application-global": "^1.0.5",
4444
"ember-load-initializers": "^0.6.0",
45+
"ember-lodash": "^4.17.5",
4546
"ember-resolver": "^2.0.3",
4647
"ember-source": "^2.12.0",
4748
"loader.js": "^4.2.3"

0 commit comments

Comments
 (0)