Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

Commit 76710db

Browse files
author
Justin Slattery
committed
Fix pager bug, separate cssClass into header/row
- Fix bug where filtering from a page > 1 could leave user on a non-existant page - Separate cssClass column def property into headerCssClass and rowCssClass - Update to React 0.14.1 - Update Readme.md
1 parent 96c75a3 commit 76710db

File tree

3 files changed

+60
-22
lines changed

3 files changed

+60
-22
lines changed

README.md

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# tabletable
22

3-
## Reactjs Simple Table
3+
## React Simple Table
4+
tabletable is a simple table component written purely in React. It is the result of my frustrations with Griddle and other React tables that are overly prescriptive in how they must be used and make things very difficult to customize and integrate into complex applications.
45

5-
tabletable is a simple table component written purely in ReactJS. It is the result of my frustrations with Griddle and other React tables that are overly prescriptive in how they must be used and make things very difficult to customize and integrate into complex applications.
6-
7-
tabletable takes any sort of data structure (provided it is Immutable) and allows you to define your columns' markup and data projections as you like. It is also server-side rendering friendly.
6+
tabletable takes any sort of data structure and allows you to define your columns' markup and data projections as you like. It is also server-side rendering friendly.
87

98
tabletable has some limitations that I hope to address in the future:
109
- It requires an Immutablejs data structure for its data
@@ -14,29 +13,65 @@ tabletable has some limitations that I hope to address in the future:
1413
If you are interested in helping with any of this, I would gladly take pull requests.
1514

1615
## Using it
17-
1816
To use tabletable:
1917
- Install the component through NPM
2018
- Require it
2119
- Pass it an Immutablejs Sequence of rows, a column definition object, and an optional filter handler.
2220

23-
Example:
21+
### Component props
22+
tabletable has the following component props:
23+
24+
#### Required
25+
**data [Immutable.Seq]** - structured source data.
26+
27+
**columns [object]** - column definition object.
28+
29+
#### Optional
30+
**rowsPerPage [number]** - number of rows to display per page.
31+
32+
**pagerSize [number]** - number pages to display in pager.
33+
34+
**showPager [bool]** - show/hide the pager.
35+
36+
**showFilter [bool]** - show/hide the filter input.
37+
38+
**pager [React.Component]** - pager component to use in place of default pager.
39+
40+
**onFilterAction [func(filterValue: string)]** - callback function for responding to filter input.
2441

42+
**filterValue [string]** - text to display in search filter.
43+
44+
### Column definition options
45+
Column definitions are a flexible way to get some fairly complex behaviors into the table while also allowing the *shape* of the data to be however you prefer. Each column defines a function that receives the row data and index as arguments and returns a React component that displays the content. This means that you can drive complex behaviors from the state and props of the parent component. The properties available in the definition objects are:
46+
47+
#### Required
48+
**data [func(row: object, index: number)]** - a function that transforms the row data into a React component to be displayed.
49+
50+
#### Optional
51+
**display [string]** - Header value for column. If not defined, the property name for the column object will be used instead.
52+
53+
**headerCssClass [string]** - CSS class(es) to use for header column (th) element.
54+
55+
**rowCssClass [string]** - CSS class(es) to use for row column (td) element.
56+
57+
**visible [bool]** - show/hide the column.
58+
59+
### Contrived Example
2560
let columnDefs = {
2661
index: {
2762
display: 'Index',
28-
cssClass: 'col-sm-1',
63+
headerCssClass: 'col-sm-1',
2964
visible: true,
3065
data: (row,index) => <div>{index}</div>,
3166
},
3267
name: {
3368
display: 'Name',
34-
cssClass: 'col-sm-10',
69+
headerCssClass: 'col-sm-10',
3570
data: row => <div>{row.get('name')}</div>,
3671
},
3772
timestamp: {
3873
display: 'Created',
39-
cssClass: 'col-sm-1',
74+
headerCssClass: 'col-sm-1',
4075
data: row => <div>{row.get('timestamp')}</div>,
4176
},
4277
};
@@ -77,7 +112,6 @@ You can also define a custom pager that will be substituted for the default page
77112
The custom pager needs to behave similarly and accept the same props as the default pager. I suggest you copy src/Pager.jsx and modify to suit your needs.
78113

79114
## Contributing
80-
81115
First, setup your local environment:
82116

83117
git clone git@github.com:ZeroarcSoftware/tabletable.git
@@ -92,9 +126,9 @@ To watch for changes:
92126

93127
npm run watch
94128

95-
## Todo
129+
## Issues
130+
Issues are tracked in [Github Issues](https://github.com/ZeroarcSoftware/tabletable/issues)
131+
132+
## Changes
133+
Changes are tracked as [Github Releases](https://github.com/ZeroarcSoftware/tabletable/releases)
96134

97-
- More examples/documentation around options
98-
- Make tabletable handle non-Immutablejs data structures
99-
- Remove/optionalize Bootstrap styling
100-
- Make all markup swappable for custom components

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tabletable",
3-
"version": "0.1.1",
4-
"description": "A simple, but extremely flexible table component written in ReactJS.",
3+
"version": "0.2.0",
4+
"description": "A simple and extremely flexible table component written in React.",
55
"main": "dist/entry.js",
66
"scripts": {
77
"build": "$(npm bin)/babel --optional es7.decorators src/ -d dist/",
@@ -24,13 +24,13 @@
2424
},
2525
"homepage": "https://github.com/ZeroarcSoftware/tabletable#readme",
2626
"devDependencies": {
27-
"babel": "^5.8.23"
27+
"babel": "^5.8.29"
2828
},
2929
"dependencies": {
3030
"autobind-decorator": "^1.3.2",
3131
"classnames": "^2.2.0",
3232
"immutable": "^3.7.5",
33-
"react": "^0.14.0",
34-
"react-addons-shallow-compare": "^0.14.0"
33+
"react": "^0.14.1",
34+
"react-addons-shallow-compare": "^0.14.1"
3535
}
3636
}

src/Container.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class TabletableContainer extends React.Component {
3737
// If visible is false, hide the column. If visible is not defined, default to showing column
3838
if (typeof this.props.columns[k].visible === 'undefined' || this.props.columns[k].visible) {
3939
headerComponents.push(
40-
<th key={`th-${k}`} className={this.props.columns[k].cssClass}>{this.props.columns[k].display || k}</th>
40+
<th key={`th-${k}`} className={this.props.columns[k].headerCssClass}>{this.props.columns[k].display || k}</th>
4141
);
4242
}
4343
});
@@ -52,7 +52,7 @@ export default class TabletableContainer extends React.Component {
5252
// If visible is false, hide the column. If visible is not defined, default to showing column
5353
if (typeof this.props.columns[k].visible === 'undefined' || this.props.columns[k].visible) {
5454
rowComponents.push(
55-
<td key={`${index}-${k}`} className={this.props.columns[k].cssClass}>{this.props.columns[k].data(row,index)}</td>
55+
<td key={`${index}-${k}`} className={this.props.columns[k].rowCssClass}>{this.props.columns[k].data(row,index)}</td>
5656
);
5757
}
5858
});
@@ -132,11 +132,15 @@ export default class TabletableContainer extends React.Component {
132132
// Update local state and call external onFilterAction if defined
133133
handleFilterChange(e) {
134134
e.stopPropagation();
135+
// Reset to first page in case we end up with less pages than current page number
136+
this.setState({currentPage: 1});
135137
this.props.onFilterAction && this.props.onFilterAction(e.target.value);
136138
}
137139

138140
handleClearFilterClick(e) {
139141
e.stopPropagation();
142+
// Reset to first page to re-orient user
143+
this.setState({currentPage: 1});
140144
this.props.onFilterAction && this.props.onFilterAction('');
141145
}
142146
}

0 commit comments

Comments
 (0)