riot-md-table
Material Design table component, for Riot.js
Work In Progress / Incomplete
Installation
bower install riot-md-table
or
npm install riot-md-table
Usage
<md-table data="{ data }" search="true" actions="4" onclick="{ onClick }">
<md-table-col label="Col1" key="key1" order="desc" />
<md-table-col label="Col2" key="key2" />
<md-table-col label="Col3" key="key3" render="{ toDollars }" />
<md-table-col label="Col4" key="key4" sorter="{ string }" />
<md-table-col label="Actions" />
</md-table>
this.data = [
{ id: "id1", key1: "val1", key2: "val2", key3: "val3", key4: "val4" },
{ id: "id2", key1: "val1", key2: "val2", key3: "val3", key4: "val4" },
{ key1: "val1", key2: "val2", key3: "val3", key4: "val4" },
{ key1: "val1", key2: "val2", key3: "val3", key4: "val4" }
]
this.string = function (a, b) {
return a.localeStringCompare(b);
}
this.toDollars = function (val) {
return '
Options
For md-table
data
Type: Array
Default: []
Required: true
Table's data, an Array of Objects.
Each data Object should be the key:value pairs for a single row. These key names are used by md-table-col tags to select a data value.
An optional id key may be used to set the id attribute of the <tr> element.
data[ Object.id ]
Type: Mixed
Default: tr-{ index }
Required: false
If not set, the data object's index (within all of data) becomes the row's id: tr-{index}.
this.data = [
{name: 'John', age: 32, job: 'Worker Bee'},
{id: 'queen', name: 'Sally', age: 26, job: 'Queen Bee'}
{name: 'Jack', age: 19, job: 'Worker Bee'},
];
<tbody>
<tr id="tr-0">
<td>John</td>
<td>32</td>
<td>Worker Bee</td>
</tr>
<tr id="queen">
<td>Sally</td>
<td>26</td>
<td>Queen Bee</td>
</tr>
<tr id="tr-2">
<td>Jack</td>
<td>19</td>
<td>Worker Bee</td>
</tr>
</tbody>
search
Type: String
Default: null
Required: false
If set (any string is truthy), displays a search <input> that can be used to search the table rows for values.
Using space and , are synonymous with OR:
"aaa bbb" === "aaa,bbb" === "aaa, bbb" ===> Show any rows whose cells contain `aaa` OR `bbb`
actions
Type: Integer
Default: null
Required: false
If table has an "Actions" column (does not contain data), pass its column index here. 0 based.
onclick
Type: Function
Default: null
Required: false
Event handler for every <td> or <tr> within <tbody>. The event's event.item value will always be a <tr> node, even if a child cell triggered the click.
For md-table-col
label
Type: String
Required: true
The column's title.
width
Type: String
Default: auto
Required: false
The column's width. Pixel or percentage widths are allowed.
key
Type: String
Required: sometimes
The key corresponds to a data object key. Required if the column is meant to display data.
order
Type: String
Default: asc
Options: asc or desc
Required: false
The first direction when sorting.
For example, if desc, the first click on <th> will sort the column values in descending order. The second click will sort the values in ascending order.
render
Type: Function
Required: false
A custom function to manipulate the cell's original value. Useful for applying prefixes or suffixes to values.
The cell's original value will always be assigned as value to the <td> element, even if a render method is used.
<md-table>
<md-table-col label="Value" render="{ toDollars }" />
</md-table>
<!-- method prepends all values with a '
After mount:
<td width="auto">
<div class="td__inner">$100.00</div>
</td>
console.log(td.value); // 100
sorter
Type: Function
Required: false
The sorting function used to arrange a column by its values. If not set then no sorting will occur when <th> is clicked.
License
MIT Luke Edwards
+ val;
}
this.onClick = function (e) {
console.log('extra `click` listener for each row: ', e.item);
}
Options
For __INLINE_CODE_0__
data
Type: __INLINE_CODE_1__
Default: __INLINE_CODE_2__
Required: __INLINE_CODE_3__
Table's data, an __INLINE_CODE_4__ of __INLINE_CODE_5__s.
Each __INLINE_CODE_6__ Object should be the __INLINE_CODE_7__ pairs for a single row. These __INLINE_CODE_8__ names are used by __INLINE_CODE_9__ tags to select a data value.
An optional __INLINE_CODE_10__ key may be used to set the __INLINE_CODE_11__ attribute of the __INLINE_CODE_12__ element.
data[ Object.id ]
Type: __INLINE_CODE_13__
Default: __INLINE_CODE_14__
Required: __INLINE_CODE_15__
If not set, the data object's index (within all of __INLINE_CODE_16__) becomes the row's id: __INLINE_CODE_17__.
__CODE_BLOCK_3__
__CODE_BLOCK_4__
search
Type: __INLINE_CODE_18__
Default: __INLINE_CODE_19__
Required: __INLINE_CODE_20__
If set (any string is truthy), displays a search __INLINE_CODE_21__ that can be used to search the table rows for values.
Using __INLINE_CODE_22__ and __INLINE_CODE_23__ are synonymous with __INLINE_CODE_24__:
__CODE_BLOCK_5__
actions
Type: __INLINE_CODE_25__
Default: __INLINE_CODE_26__
Required: __INLINE_CODE_27__
If table has an "Actions" column (does not contain data), pass its column index here. 0 based.
onclick
Type: __INLINE_CODE_28__
Default: __INLINE_CODE_29__
Required: __INLINE_CODE_30__
Event handler for every __INLINE_CODE_31__ or __INLINE_CODE_32__ within __INLINE_CODE_33__. The event's __INLINE_CODE_34__ value will always be a __INLINE_CODE_35__ node, even if a child cell triggered the __INLINE_CODE_36__.
For __INLINE_CODE_37__
label
Type: __INLINE_CODE_38__
Required: __INLINE_CODE_39__
The column's title.
width
Type: __INLINE_CODE_40__
Default: __INLINE_CODE_41__
Required: __INLINE_CODE_42__
The column's width. Pixel or percentage widths are allowed.
key
Type: __INLINE_CODE_43__
Required: __INLINE_CODE_44__
The __INLINE_CODE_45__ corresponds to a __INLINE_CODE_46__ object key. Required if the column is meant to display data.
order
Type: __INLINE_CODE_47__
Default: __INLINE_CODE_48__
Options: __INLINE_CODE_49__ or __INLINE_CODE_50__
Required: __INLINE_CODE_51__
The first direction when sorting.
For example, if __INLINE_CODE_52__, the first click on __INLINE_CODE_53__ will sort the column values in descending order. The second click will sort the values in ascending order.
render
Type: __INLINE_CODE_54__
Required: __INLINE_CODE_55__
A custom function to manipulate the cell's original value. Useful for applying prefixes or suffixes to values.
The cell's original value will always be assigned as __INLINE_CODE_56__ to the __INLINE_CODE_57__ element, even if a __INLINE_CODE_58__ method is used.
__CODE_BLOCK_6__
After __INLINE_CODE_59__:
__CODE_BLOCK_7__
__CODE_BLOCK_8__
sorter
Type: __INLINE_CODE_60__
Required: __INLINE_CODE_61__
The sorting function used to arrange a column by its values. If not set then no sorting will occur when __INLINE_CODE_62__ is clicked.
License
MIT Luke Edwards
and appends '.00' -->
this.toDollars = function (val) {
return '
After __INLINE_CODE_59__:
__CODE_BLOCK_7__
__CODE_BLOCK_8__
sorter
Type: __INLINE_CODE_60__
Required: __INLINE_CODE_61__
The sorting function used to arrange a column by its values. If not set then no sorting will occur when __INLINE_CODE_62__ is clicked.
License
MIT Luke Edwards
+ val;
}
this.onClick = function (e) {
console.log('extra `click` listener for each row: ', e.item);
}
Options
For __INLINE_CODE_0__
data
Type: __INLINE_CODE_1__
Default: __INLINE_CODE_2__
Required: __INLINE_CODE_3__
Table's data, an __INLINE_CODE_4__ of __INLINE_CODE_5__s.
Each __INLINE_CODE_6__ Object should be the __INLINE_CODE_7__ pairs for a single row. These __INLINE_CODE_8__ names are used by __INLINE_CODE_9__ tags to select a data value.
An optional __INLINE_CODE_10__ key may be used to set the __INLINE_CODE_11__ attribute of the __INLINE_CODE_12__ element.
data[ Object.id ]
Type: __INLINE_CODE_13__
Default: __INLINE_CODE_14__
Required: __INLINE_CODE_15__
If not set, the data object's index (within all of __INLINE_CODE_16__) becomes the row's id: __INLINE_CODE_17__.
__CODE_BLOCK_3__ __CODE_BLOCK_4__search
Type: __INLINE_CODE_18__
Default: __INLINE_CODE_19__
Required: __INLINE_CODE_20__
If set (any string is truthy), displays a search __INLINE_CODE_21__ that can be used to search the table rows for values.
Using __INLINE_CODE_22__ and __INLINE_CODE_23__ are synonymous with __INLINE_CODE_24__:
__CODE_BLOCK_5__actions
Type: __INLINE_CODE_25__
Default: __INLINE_CODE_26__
Required: __INLINE_CODE_27__
If table has an "Actions" column (does not contain data), pass its column index here. 0 based.
onclick
Type: __INLINE_CODE_28__
Default: __INLINE_CODE_29__
Required: __INLINE_CODE_30__
Event handler for every __INLINE_CODE_31__ or __INLINE_CODE_32__ within __INLINE_CODE_33__. The event's __INLINE_CODE_34__ value will always be a __INLINE_CODE_35__ node, even if a child cell triggered the __INLINE_CODE_36__.
For __INLINE_CODE_37__
label
Type: __INLINE_CODE_38__
Required: __INLINE_CODE_39__
The column's title.
width
Type: __INLINE_CODE_40__
Default: __INLINE_CODE_41__
Required: __INLINE_CODE_42__
The column's width. Pixel or percentage widths are allowed.
key
Type: __INLINE_CODE_43__
Required: __INLINE_CODE_44__
The __INLINE_CODE_45__ corresponds to a __INLINE_CODE_46__ object key. Required if the column is meant to display data.
order
Type: __INLINE_CODE_47__
Default: __INLINE_CODE_48__
Options: __INLINE_CODE_49__ or __INLINE_CODE_50__
Required: __INLINE_CODE_51__
The first direction when sorting.
For example, if __INLINE_CODE_52__, the first click on __INLINE_CODE_53__ will sort the column values in descending order. The second click will sort the values in ascending order.
render
Type: __INLINE_CODE_54__
Required: __INLINE_CODE_55__
A custom function to manipulate the cell's original value. Useful for applying prefixes or suffixes to values.
The cell's original value will always be assigned as __INLINE_CODE_56__ to the __INLINE_CODE_57__ element, even if a __INLINE_CODE_58__ method is used.
__CODE_BLOCK_6__After __INLINE_CODE_59__:
__CODE_BLOCK_7__ __CODE_BLOCK_8__sorter
Type: __INLINE_CODE_60__
Required: __INLINE_CODE_61__
The sorting function used to arrange a column by its values. If not set then no sorting will occur when __INLINE_CODE_62__ is clicked.
License
MIT Luke Edwards
+ val + '.00'; }After __INLINE_CODE_59__:
__CODE_BLOCK_7__ __CODE_BLOCK_8__sorter
Type: __INLINE_CODE_60__
Required: __INLINE_CODE_61__
The sorting function used to arrange a column by its values. If not set then no sorting will occur when __INLINE_CODE_62__ is clicked.
License
MIT Luke Edwards
+ val; } this.onClick = function (e) { console.log('extra `click` listener for each row: ', e.item); }Options
For __INLINE_CODE_0__
data
Type: __INLINE_CODE_1__
Default: __INLINE_CODE_2__
Required: __INLINE_CODE_3__
Table's data, an __INLINE_CODE_4__ of __INLINE_CODE_5__s.
Each __INLINE_CODE_6__ Object should be the __INLINE_CODE_7__ pairs for a single row. These __INLINE_CODE_8__ names are used by __INLINE_CODE_9__ tags to select a data value.
An optional __INLINE_CODE_10__ key may be used to set the __INLINE_CODE_11__ attribute of the __INLINE_CODE_12__ element.
data[ Object.id ]
Type: __INLINE_CODE_13__
Default: __INLINE_CODE_14__
Required: __INLINE_CODE_15__
If not set, the data object's index (within all of __INLINE_CODE_16__) becomes the row's id: __INLINE_CODE_17__.
__CODE_BLOCK_3__ __CODE_BLOCK_4__search
Type: __INLINE_CODE_18__
Default: __INLINE_CODE_19__
Required: __INLINE_CODE_20__
If set (any string is truthy), displays a search __INLINE_CODE_21__ that can be used to search the table rows for values.
Using __INLINE_CODE_22__ and __INLINE_CODE_23__ are synonymous with __INLINE_CODE_24__:
__CODE_BLOCK_5__actions
Type: __INLINE_CODE_25__
Default: __INLINE_CODE_26__
Required: __INLINE_CODE_27__
If table has an "Actions" column (does not contain data), pass its column index here. 0 based.
onclick
Type: __INLINE_CODE_28__
Default: __INLINE_CODE_29__
Required: __INLINE_CODE_30__
Event handler for every __INLINE_CODE_31__ or __INLINE_CODE_32__ within __INLINE_CODE_33__. The event's __INLINE_CODE_34__ value will always be a __INLINE_CODE_35__ node, even if a child cell triggered the __INLINE_CODE_36__.
For __INLINE_CODE_37__
label
Type: __INLINE_CODE_38__
Required: __INLINE_CODE_39__
The column's title.
width
Type: __INLINE_CODE_40__
Default: __INLINE_CODE_41__
Required: __INLINE_CODE_42__
The column's width. Pixel or percentage widths are allowed.
key
Type: __INLINE_CODE_43__
Required: __INLINE_CODE_44__
The __INLINE_CODE_45__ corresponds to a __INLINE_CODE_46__ object key. Required if the column is meant to display data.
order
Type: __INLINE_CODE_47__
Default: __INLINE_CODE_48__
Options: __INLINE_CODE_49__ or __INLINE_CODE_50__
Required: __INLINE_CODE_51__
The first direction when sorting.
For example, if __INLINE_CODE_52__, the first click on __INLINE_CODE_53__ will sort the column values in descending order. The second click will sort the values in ascending order.
render
Type: __INLINE_CODE_54__
Required: __INLINE_CODE_55__
A custom function to manipulate the cell's original value. Useful for applying prefixes or suffixes to values.
The cell's original value will always be assigned as __INLINE_CODE_56__ to the __INLINE_CODE_57__ element, even if a __INLINE_CODE_58__ method is used.
__CODE_BLOCK_6__After __INLINE_CODE_59__:
__CODE_BLOCK_7__ __CODE_BLOCK_8__sorter
Type: __INLINE_CODE_60__
Required: __INLINE_CODE_61__
The sorting function used to arrange a column by its values. If not set then no sorting will occur when __INLINE_CODE_62__ is clicked.
License
MIT Luke Edwards