Skip to content

Commit 0163a7b

Browse files
Merge pull request #114 from MyPureCloud/custom-components
Custom components
2 parents afd61b7 + 3f286ba commit 0163a7b

File tree

10 files changed

+72
-12
lines changed

10 files changed

+72
-12
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,33 @@ Alternatively, you skip calling `this.bubbleAction` in the cell component's Java
289289
290290
This will directly bubble the action with name `myActionName` to the parent of the `fixtable-grid` component, passing along any additional arguments that follow the action name.
291291
292+
### Additional Custom Components
293+
294+
#### Footer Component
295+
296+
You can supply your own `footerComponent` which will be rendered in place of the default `fixtable-footer` component. The following properties will be made available to your custom footer:
297+
298+
* `currentPage` - integer value of the currently selected page (starting at 1)
299+
* `totalRows` - integer value of the total number of rows; if you're using server-side paging, this will be equal to `totalRowsOnServer`, otherwise it's the number of rows in the current filtered content array
300+
* `totalPages` - integer value of the number of available pages given the current `pageSize` and `totalRows`
301+
* `selectedDataRows` - array of the currently selected row objects
302+
* `pageSize` - integer value of the number of items in each page
303+
* `pageSizeOptions` - array of integers which can optionally be used to provide the user an affordance for changing `pageSize`
304+
* `isLoading` - boolean value to indicate when a new page is being loaded (it's up to your `onReloadContent` method to update this value)
305+
* `goToNextPage` - action which your component may invoke to increment the currentPage
306+
* `goToPreviousPage` - action which your component may invoke to decrement the currentPage
307+
* `bubbleAction` - action which your component may invoke to bubble actions up to the consumer of the fixtable-grid (this works the same as custom cell components; see [Bubbling Actions from Custom Cell components](#bubbling-actions-from-custom-cell-components) above)
308+
309+
#### Empty State Component
310+
311+
You can supply your own `emptyStateComponent` which will be rendered in place of the default `fixtable-empty-state` component when the content array is empty. You can also supply an object using the `emptyStateComponentValues` property with dynamic values to be passed along to your component as `values`.
312+
313+
The default empty state component simply shows a message, centered vertically and horizontally within Fixtable. This message defaults to "No data available", but you can override it by using the `emptyStateComponentValues` property to set an object with a `nullMessage` property. For example:
314+
315+
```
316+
{{fixtable-grid emptyStateComponentValues={nullMessage: "Nothing to see here!"}}}
317+
```
318+
292319
### Filtering
293320
294321
Fixtable supports filtering the displayed rows, either by search text or by selected option. To set this up, add a filter property to the column definition.
@@ -609,6 +636,10 @@ Because "expanded" rows are actually rendered as two table rows, Fixtable takes
609636
* `hover` - present on both row elements when the user's cursor is hovering over _either_ row element (you should use this class rather than relying on the `:hover` pseudo-class if you want to use hover styles with expanded rows)
610637
* `active` - present on both row elements if the row is selected (see [Row Selection](#row-selection) above)
611638
639+
### Debugging
640+
641+
Fixtable-Ember utilizes the core [Fixtable](https://github.com/MyPureCloud/fixtable-core) library to handle the low-level DOM manipulation required for the fixed-header effect, ensuring Fixtable is styled to match your application's tables, etc. If you notice rendering issues, they're likely to originate in this core library and not Fixtable-Ember itself. If you set the `debugMode` property to `true` on your `fixtable-grid` component, it will enable debug logs on its internal `Fixtable` object which may be helpful in diagnosing issues.
642+
612643
## Development / Contributing
613644
614645
### Installation
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Ember from 'ember';
2+
import layout from '../templates/components/fixtable-empty-state';
3+
4+
export default Ember.Component.extend({
5+
layout
6+
});

addon/components/fixtable-footer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import layout from '../templates/components/fixtable-footer';
33

44
export default Ember.Component.extend({
55
layout,
6-
classNames: ['fixtable-footer'],
76
currentPage: null,
87
totalPages: null,
98
pageSize: null,

addon/components/fixtable-grid.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default Ember.Component.extend({
1616
layout: layout,
1717
fixtable: null,
1818
columnsByKey: null,
19-
nullMessage: "No data available",
19+
debugMode: false,
2020

2121
// paging
2222
clientPaging: false,
@@ -42,6 +42,18 @@ export default Ember.Component.extend({
4242
selectedRowMap: null, // maps row indices to selected state
4343
suppressSelectToggle: false,
4444

45+
// custom components
46+
emptyStateComponent: 'fixtable-empty-state',
47+
emptyStateComponentValues: {nullMessage: 'No data available'},
48+
footerComponent: 'fixtable-footer',
49+
50+
// backwards-compatibility for old nullMessage option
51+
// TODO: remove this in fixtable-ember v4.0.0
52+
nullMessageChanged: Ember.observer('nullMessage', function () {
53+
Ember.Logger.warn('Deprecation warning: use emptyStateComponentValues instead of nullMessage. Support will be dropped in fixtable-ember v4.x. See https://github.com/MyPureCloud/fixtable-ember#empty-state-component for more info.');
54+
this.set('emptyStateComponentValues.nullMessage', this.get('nullMessage'));
55+
}),
56+
4557
externalFilters: null,
4658

4759
currentPage: defaultPage,
@@ -339,9 +351,12 @@ export default Ember.Component.extend({
339351
},
340352

341353
notifyRowSelectionChanged(selectedDataRows) {
354+
this.set('selectedDataRows', selectedDataRows.map((row) => {
355+
return row.object;
356+
}));
342357
let handler = this.get('onSelectionChanged');
343358
if (typeof handler === 'function') {
344-
handler(selectedDataRows.map((row) => {return row.object;}));
359+
handler(this.get('selectedDataRows'));
345360
}
346361
},
347362

@@ -438,7 +453,7 @@ export default Ember.Component.extend({
438453

439454
initializeFixtable() {
440455
// initialize the Fixtable script
441-
let fixtable = new Fixtable(this.$('.fixtable')[0]);
456+
let fixtable = new Fixtable(this.$('.fixtable')[0], this.get('debugMode'));
442457

443458
// account for the row selection checkbox column, if present
444459
let indexOffset = 1;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h4>
2+
{{values.nullMessage}}
3+
</h4>

addon/templates/components/fixtable-grid.hbs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,16 @@
108108
<span class="sr-only">Loading...</span>
109109
{{else}}
110110
{{#unless visibleContent.length}}
111-
<h4>{{nullMessage}}</h4>
111+
{{component emptyStateComponent values=emptyStateComponentValues}}
112112
{{/unless}}
113113
{{/if}}
114114
</div>
115115
</div>
116-
{{#if showPaginationFooter}}
117-
{{fixtable-footer
118-
currentPage=currentPage totalPages=totalPages pageSize=pageSize pageSizeOptions=pageSizeOptions
116+
<div class="fixtable-footer {{unless showPaginationFooter 'fixtable-footer-hidden'}}">
117+
{{component footerComponent
118+
currentPage=currentPage totalPages=totalPages totalRows=totalRows
119+
isLoading=isLoading pageSize=pageSize pageSizeOptions=pageSizeOptions
120+
selectedDataRows=selectedDataRows bubbleAction=(action sendAction)
119121
goToNextPage="goToNextPage" goToPreviousPage="goToPreviousPage"}}
120-
{{/if}}
122+
</div>
121123
</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from 'fixtable-ember/components/fixtable-empty-state';

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fixtable-ember",
3-
"version": "3.3.0",
3+
"version": "3.4.0",
44
"description": "Ember wrapper for the Fixtable table library",
55
"directories": {
66
"doc": "doc",

tests/integration/components/fixtable-footer-test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ test('it renders', function(assert) {
1414
this.set('pageSize', 25);
1515
this.set('pageSizeOptions', [25, 50, 100]);
1616

17-
this.render(hbs`{{fixtable-footer currentPage=currentPage totalPages=totalPages pageSize=pageSize pageSizeOptions=pageSizeOptions}}`);
18-
17+
this.render(hbs`{{fixtable-footer class='fixtable-footer' currentPage=currentPage totalPages=totalPages pageSize=pageSize pageSizeOptions=pageSizeOptions}}`);
1918
assert.ok(this.$('.fixtable-footer').length); // there is an element with the fixtable-footer class
2019
});

vendor/styles/fixtable-ember.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
background-color: white;
3030
}
3131

32+
.fixtable .fixtable-footer-hidden {
33+
display: none;
34+
}
35+
3236
.fixtable .fixtable-footer {
3337
padding: 5px;
3438
}

0 commit comments

Comments
 (0)