Skip to content

Commit 084c956

Browse files
Merge pull request #108 from MyPureCloud/expandable-rows
Expandable Rows
2 parents 8e861ce + 7c64be4 commit 084c956

29 files changed

+213
-21
lines changed

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ For example:
108108

109109
```css
110110
.restrict-height {
111-
height: 400px;
111+
height: 500px;
112112
}
113113
```
114114

@@ -250,7 +250,11 @@ For example, here we have two regular columns and a third "profile" column that
250250
]
251251
```
252252
253-
Custom cell components will automatically be provided with two properties: `columnDef` and `dataRow`. These properties are exactly what they sound like -- the column definition and data row for the cell, respectively.
253+
Custom cell components will automatically be provided with three properties:
254+
255+
* `columnDef` - the column definition
256+
* `dataRow` - the object from the `content` array represented by this row
257+
* `rowExpanded` - a boolean value indicating whether or not the row is expanded (more on this in the [Row Expansion](#row-expansion) section below)
254258
255259
For example, the Handlebars markup for the example `link-to-profile` component could look like this:
256260
```handlebars
@@ -577,7 +581,21 @@ Consumers should keep track of which rows are selected by subscribing to `onSele
577581
578582
### Row Clicking
579583
For simple row click interaction without showing the row checkbox `onRowClick` should be bound to an action on the owning controller or component. The bound action will be called whenever the row is clicked. It receives the following parameter:
580-
* `clickedRow` (Object) the data object for the row that was clicked.
584+
* `clickedRow` (Object) the data object for the row that was clicked.
585+
586+
### Row Expansion
587+
588+
Fixtable has built-in support for expandable rows, for cases where you may desire to show more information than can comfortably fit on a single row. When a row is "expanded," a second, full-width table row is displayed beneath the normal row. In this expanded space, Fixtable will render whatever custom component you specify in the `expandedRowComponent` property. This component will receive the same `dataRow` binding as any custom cell component in the main row (see [Custom Cell Components](#custom-cell-components) above).
589+
590+
To allow for toggling rows between expanded and collapsed state, you should include a component in one of your column definitions that toggles the `rowExpanded` property. Fixtable includes a simple component, `fixtable-row-toggle`, that you can use for this purpose. You can also make a custom component if you need additional logic or prefer a different design. It's also noteworthy that any custom cell component can read and write the `rowExpanded` property, so you can toggle or react to this value in multiple columns if needed.
591+
592+
Because "expanded" rows are actually rendered as two table rows, Fixtable takes some steps to ensure you can still style them as desired. For one thing, any border between the two rows will be removed by default to maintain the illusion of a single row (this can, naturally, be overridden in your own CSS). Fixtable also applies some helpful CSS classes to each row element:
593+
594+
* `fixtable-row-primary` - the primary, multi-column row (rendered from your column definition)
595+
* `fixtable-row-secondary` - the second, full-width column that renders your `expandedRowComponent`
596+
* `expanded` - present on both row elements when the dataRow is expanded
597+
* `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)
598+
* `active` - present on both row elements if the row is selected (see [Row Selection](#row-selection) above)
581599
582600
## Development / Contributing
583601

addon/components/fixtable-grid.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,19 @@ export default Ember.Component.extend({
230230
sortedFilteredContent = sortedFilteredContent.slice((currentPage - 1) * pageSize, currentPage * pageSize);
231231
}
232232

233-
return sortedFilteredContent;
233+
return sortedFilteredContent.map(function (rowObject) {
234+
return {
235+
object: rowObject,
236+
hover: false,
237+
expanded: false
238+
};
239+
});
234240
}),
235241

242+
totalColumns: Ember.computed('columns.[]', 'rowSelection', function fixtableGrid$totalColumns() {
243+
return this.get('columns').length + (this.get('rowSelection') ? 1 : 0);
244+
}),
245+
236246
totalRows: Ember.computed('sortedFilteredContent.[]', 'serverPaging', 'totalRowsOnServer',
237247
function fixtableGrid$totalRows() {
238248
if (this.get('serverPaging')) {
@@ -316,7 +326,7 @@ export default Ember.Component.extend({
316326
notifyRowSelectionChanged(selectedDataRows) {
317327
let handler = this.get('onSelectionChanged');
318328
if (typeof handler === 'function') {
319-
handler(selectedDataRows);
329+
handler(selectedDataRows.map((row) => {return row.object;}));
320330
}
321331
},
322332

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Ember from 'ember';
2+
import layout from '../templates/components/fixtable-row-toggle';
3+
4+
export default Ember.Component.extend({
5+
layout,
6+
classNames: ['fixtable-row-toggle'],
7+
click: function() {
8+
this.toggleProperty('rowExpanded');
9+
}
10+
});

addon/components/fixtable-row.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Ember from 'ember';
2+
import layout from '../templates/components/fixtable-row';
3+
4+
export default Ember.Component.extend({
5+
layout,
6+
tagName: 'tr',
7+
classNames: ['fixtable-row'],
8+
classNameBindings: ['active', 'expanded', 'hover', 'primary:fixtable-row-primary:fixtable-row-secondary'],
9+
click() {
10+
this.get('onClick')();
11+
},
12+
mouseEnter() {
13+
this.set('hover', true);
14+
},
15+
mouseLeave() {
16+
this.set('hover', false);
17+
}
18+
});

addon/templates/components/fixtable-grid.hbs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<tbody>
6969
{{#unless isLoading}}
7070
{{#each visibleContent as |row rowIndex|}}
71-
<tr class={{if (get selectedRowMap (concat '' rowIndex)) 'active'}} {{action 'onRowClick' row preventDefault=false}}>
71+
{{#fixtable-row primary=true hover=row.hover expanded=row.expanded active=(get selectedRowMap (concat '' rowIndex)) onClick=(action 'onRowClick' row.object)}}
7272
{{#if rowSelection}}
7373
<td>
7474
<div class="fixtable-checkbox">
@@ -81,14 +81,23 @@
8181
<td class={{column.cellClass}}>
8282
{{#if column.component}}
8383
{{!-- render the passed-in component --}}
84-
{{component column.component dataRow=row columnDef=column bubbleAction=(action sendAction)}}
84+
{{component column.component dataRow=row.object rowExpanded=row.expanded columnDef=column bubbleAction=(action sendAction)}}
8585
{{else}}
8686
{{!-- directly render the cell --}}
87-
{{get row column.key}}
87+
<span>{{get row.object column.key}}</span>
8888
{{/if}}
8989
</td>
9090
{{/each}}
91-
</tr>
91+
{{/fixtable-row}}
92+
{{#if row.expanded}}
93+
{{#if expandedRowComponent}}
94+
{{#fixtable-row primary=false hover=row.hover expanded=row.expanded active=(get selectedRowMap (concat '' rowIndex))}}
95+
<td colspan="{{totalColumns}}">
96+
{{component expandedRowComponent dataRow=row.object}}
97+
</td>
98+
{{/fixtable-row}}
99+
{{/if}}
100+
{{/if}}
92101
{{/each}}
93102
{{/unless}}
94103
</tbody>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{{#if rowExpanded}}
2+
<span class="fa fa-minus-square-o"></span>
3+
{{else}}
4+
<span class="fa fa-plus-square-o"></span>
5+
{{/if}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{yield}}
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-row-toggle';

app/components/fixtable-row.js

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-row';

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.1.0",
3+
"version": "3.2.0",
44
"description": "Ember wrapper for the Fixtable table library",
55
"directories": {
66
"doc": "doc",

0 commit comments

Comments
 (0)