Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Child Row Tmpl (Sub-Tables) #403

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
170f183
Added a noprint class to header and footer section
datanotion Jan 11, 2016
f87125d
Revert "Added a noprint class to header and footer section"
datanotion Jan 11, 2016
6feedd8
Merge remote-tracking branch 'upstream/master'
ClarenceL May 3, 2016
97fdaad
add .idea to ignore
ClarenceL May 3, 2016
02b965b
importing expandable rows code from previous pull request as a starti…
ClarenceL May 3, 2016
6b9c6dd
reactive table children rework
ClarenceL May 7, 2016
a46e6fd
bugs fixes and documentation
ClarenceL May 7, 2016
334d074
bugs fixes and documentation
ClarenceL May 7, 2016
226af78
readme
ClarenceL May 13, 2016
d93c644
Rename
ClarenceL May 30, 2016
92f14ab
Rename
ClarenceL May 30, 2016
f1ab4c1
more renaming
ClarenceL May 30, 2016
d777f12
fix CSS renaming
ClarenceL May 30, 2016
ae86d4d
fixed expand/collapse
ClarenceL May 31, 2016
57feab3
add _expand/collapseChildren to tmpl too
ClarenceL May 31, 2016
85e2b33
rename
ClarenceL Jun 5, 2016
d787ce4
renaming back
ClarenceL Jun 19, 2016
dc204bf
Merge remote-tracking branch 'upstream/master'
ClarenceL Jun 19, 2016
00c339d
merge master from upstream
ClarenceL Jun 19, 2016
2299f65
mark child tmpl feature as beta
ClarenceL Jun 19, 2016
b85f2c4
added more instructions for nested reactive tables
ClarenceL Jun 20, 2016
29023d3
update readme for expand/collapseChildren helpers
ClarenceL Jun 21, 2016
0bae54c
readme formatting
ClarenceL Jun 21, 2016
83e11d6
fixed misnamed template
ClarenceL Jun 21, 2016
66a1f2b
left a debugger in
ClarenceL Jun 21, 2016
8fae5e6
Add expandIcon and collapseIcon properties to have dynamic icons, Exp…
ayselafsar Dec 1, 2016
3c441c7
Merge pull request #1 from ayselafsar/feature-child-tmpl
ClarenceL Dec 2, 2016
8195583
Check template has visible children
ayselafsar Dec 2, 2016
71d7843
Merge branch 'master' into feature-child-tmpl
ClarenceL Aug 20, 2017
6d4fc4b
Merge pull request #2 from ayselafsar/feature-child-tmpl
ClarenceL Aug 20, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.build*
.idea
212 changes: 212 additions & 0 deletions CHILD_TABLE_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@

# Child (Sub) Tables <sup>BETA</sup>

This guide shows how to add child/sub tables, this simply inserts a new row when expanded.
You can control the expand/collapse control and render an array on your data structure or
simply pass in a template for the sub table and handle it yourself.


**Requirements:**

- Your data must have a unique `_id` field, if you're using a Collection this shouldn't be an issue,
otherwise add the field and you can use `Meteor.uuid()` for example.


---

### Expand Button Setup

There are 2 implementations of the expand button


#### Simple Prepended Icon

On any field you can add the setting `expandButton`

Set `useFontAwesome = true` in the settings for a better icon
[https://github.com/aslagle/reactive-table#settings](https://github.com/aslagle/reactive-table#settings)



fields: [

{
key: 'store_name',
label: 'Store Name',
expandButton: true
},
...
]

By itself this will prepend an expand/collapse icon to the cell.

This respects the virtual column's `fn` function, if you use this it will prepend the icon to the result.



#### Custom Expand Button Template

First `expandButton` must be set to true, and if you are using a Template,
we will automatically pass in to the template data two helper functions, please note the underscore prefix
to avoid collisions. In fact the *\_.extend* I use to add these helpers prioritizes your data first, so you
can override these completely.

- `_expandChildren` - show the child / sub table
- `_collapseChildren` - hide the above

For example I can pass in my own template:

fields: [

{
key: 'store_name',
label: 'Store Name',
expandButton: true,
tmpl: Template.StoreExpandCell
},
...
]

And then in my template I can create an event, where functions `this._expandChildren` and `this._collapseChildren`
are accessible. You can save your state however you wish, in my case I am using the DOM.


Template.StoreExpandCell.events({

'click .my-expand-control': function( ev, t ){

var divContainer = $(ev.currentTarget);
var iconExpand = divContainer.find('.expand-icon');

if (!!divContainer.data('expanded')) {
iconExpand.removeClass( 'fa-minus-square-o' ).addClass( 'fa-plus-square-o' );
divContainer.data('expanded', false);
this._collapseChildren();
}
else {
iconExpand.removeClass( 'fa-plus-square-o' ).addClass( 'fa-minus-square-o' );
divContainer.data('expanded', true);
this._expandChildren();
}

}

});


---


### Child/Sub Table Setup

You have two options for the contents of the child table, either a simple table rendered with the default reactive-table fields options
or a custom template

The child table settings are added with the reactive-table setting `children`


#### Child Table

For a child table you need two settings in `children`, these are `dataField` and `fields`

`dataField` - this must be a field referencing an array of structs, for example if I have the following data,
you may notice that `store_locations` is actually an array, I don't reference it in my parent table `fields`
setting, and plan to use it to iterate over and generate my child table.

[
{
_id: 1,
store_name: 'ABC Store',
store_locations: [
{
_id: 1000,
city: 'San Francisco'
},
...
]
},
{
_id: 2,
store_name: 'Tom\'s Hardware'
store_locations: [
{
_id: 2000
city: 'Chicago'
},
{
_id: 2001,
city: 'New York'
},
{
_id: 2002,
city: 'Los Angeles'
}
...
]
}
...
]



`fields` - similar to the `fields` setting on the parent table, all the same functionality is retained such as
virtual columns, templates and styling options. It will iterate over the array referenced by the key `dataField`
and generate a row for each iteration with the `children.fields` specification.

`expandIcon` - Make expand icon customizable.<br>
`collapseIcon` - Make collapse icon customizable.

fields: [

{
key: 'store_name',
label: 'Store Name',
expandButton: true,
tmpl: Template.StoreExpandCell
},
...
],

children: {
dataField: 'store_locations',
fields: [
{
key: 'city',
label: 'Location'
}
...
],
expandIcon: 'fa fa-angle-down',
collapseIcon: 'fa fa-angle-up',
}



#### Custom Template

Simply add the template to a `children` field, and the entire data object will be passed into your specified template
for you to reference

fields: [

{
key: 'store_name',
label: 'Store Name',
expandButton: true,
tmpl: Template.StoreExpandCell
},
...
],

children: {
tmpl: Template.StoreLocations
}


### Nested Reactive Tables

You can definitely nest entire reactive tables now with the `tmpl` option, in the above example Template.StoreLocations could
simply insert another reactive table

*However if you use the `expandButton` option for controls, you need to a specify a new setting `childrenExpandIconClass` on the settings object
you pass into reactive table, this ensures the expand icons don't conflict, I'm using a DOM $.find CSS to toggle these for now*
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ You can specify a template to use to render cells in a column, by adding `tmpl`

The template's context will be the full object, so it will have access to all fields.


It's useful to note that irregardless of what's displayed by tmpl, the `fn` column field is what's used for sorting.
This allows you to handle situations where you want a custom value to sort on (`sortByValue` doesn't work) and still
want the additional formatting provided by a template.

#### Virtual columns

You can also compute a function on the attribute's value to display in the table, by adding `fn` to the field.
Expand Down
62 changes: 39 additions & 23 deletions lib/reactive_table.css
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
.reactive-table-options {
padding-right: 0px;
margin-right: -5px;
padding-right: 0px;
margin-right: -5px;
}

.reactive-table-filter {
float: right;
float: right;
}

.reactive-table-columns-dropdown {
float: right;
float: right;
}

.reactive-table-columns-dropdown button {
float: right;
float: right;
}

.reactive-table .sortable, .reactive-table-add-column {
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
.reactive-table.sortable, .reactive-table-add-column {
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

.table > thead > tr > th.reactive-table-add-column {
border-bottom: none;
border-bottom: none;
}

.reactive-table-navigation {
display: inline-block;
width: 100%;
display: inline-block;
width: 100%;
}

.reactive-table-navigation .form-inline input {
width: 45px;
width: 45px;
}

.reactive-table-navigation .rows-per-page {
float: left;
float: left;
}

.reactive-table-navigation .page-number {
float: right;
float: right;
}

.reactive-table-navigation .previous-page,
Expand All @@ -53,20 +53,36 @@

.reactive-table-navigation .previous-page.fa,
.reactive-table-navigation .next-page.fa {
vertical-align: middle;
vertical-align: middle;
}

.reactive-table-navigation .previous-page:hover,
.reactive-table-navigation .next-page:hover {
cursor: pointer;
cursor: pointer;
}

.reactive-table .fa-sort-asc {
position: relative;
top: -2px;
position: relative;
top: -2px;
}

.reactive-table .fa-sort-desc {
position: relative;
top: 2px;
position: relative;
top: 2px;
}

.reactive-table .reactive-table-children-expand {
cursor: pointer;
}

.reactive-table .reactive-table-children-container .error {
color: #d9534f;
}

.reactive-table .reactive-table-children-container td {
padding: 0;
}

.reactive-table-children {
width: 100%;
}
Loading