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

Commit 439b4aa

Browse files
committed
PreventDefault for pager buttons, readme update
Also some minor syntax changes
1 parent d4b6a58 commit 439b4aa

3 files changed

Lines changed: 42 additions & 32 deletions

File tree

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ tabletable has the following component props:
2424
#### Required
2525
**data [Immutable.Seq]** - structured source data.
2626

27-
**columns [object]** - column definition object.
27+
**columns [object[]]** - array of column definition objects.
2828

2929
#### Optional
3030
**rowsPerPage [number]** - number of rows to display per page.
@@ -61,31 +61,29 @@ Column definitions are a flexible way to get some fairly complex behaviors into
6161
**visible [bool]** - show/hide the column.
6262

6363
### Contrived Example
64-
let columnDefs = {
65-
index: {
64+
let columnDefs = [
65+
{
6666
display: 'Index',
6767
headerCssClass: 'col-sm-1',
6868
visible: true,
6969
data: (row,index,context) => <div>{index}</div>,
7070
},
71-
name: {
71+
{
7272
display: 'Name',
7373
headerCssClass: 'col-sm-10',
7474
data: row => <div>{row.get('name')}</div>,
7575
},
76-
timestamp: {
76+
{
7777
display: 'Created',
7878
headerCssClass: 'col-sm-1',
7979
data: row => <div>{row.get('timestamp')}</div>,
8080
},
81-
};
82-
81+
];
8382

8483
handleFilterAction(filterValue) {
8584
console.log('Filter value is: ' + filterValue);
8685
},
8786

88-
8987
<Tabletable
9088
data={myCrazyCustomImmutablejsDataStructure}
9189
columns={columnDefs}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tabletable",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "A simple and extremely flexible table component written in React.",
55
"main": "dist/entry.js",
66
"scripts": {

src/Pager.jsx

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,44 @@
1-
/* Copyright 2015 Zeroarc Software, LLC
2-
*
3-
* Pager control
4-
*/
1+
//@flow
2+
// tabletable - Copyright 2017 Zeroarc Software, LLC
3+
'use strict';
54

6-
// External
7-
let React = require('react');
8-
let ReactShallowCompare = require('react-addons-shallow-compare');
9-
let ClassNames = require('classnames');
10-
let Autobind = require('autobind-decorator');
5+
const React = require('react');
6+
const ReactShallowCompare = require('react-addons-shallow-compare');
7+
const ClassNames = require('classnames');
8+
const Autobind = require('autobind-decorator');
9+
10+
type Props = {
11+
displayPages: number,
12+
maxPage: number,
13+
currentPage: number,
14+
onPageChange: (page: number) => void
15+
};
1116

1217
@Autobind
1318
export default class TabletablePager extends React.Component {
14-
shouldComponentUpdate(nextProps, nextState) {
15-
return ReactShallowCompare(this, nextProps, nextState);
19+
props: Props;
20+
21+
static defaultProps: {
22+
maxPage: number,
23+
currentPage: number,
24+
}
25+
26+
shouldComponentUpdate(nextProps: Props) {
27+
return ReactShallowCompare(this, nextProps);
1628
}
1729

1830
render() {
1931
let options = [];
2032

2133
let startIndex = Math.max(this.props.currentPage - Math.floor(this.props.displayPages / 2), 1);
22-
let endIndex = Math.min(startIndex + (this.props.displayPages - 1), this.props.maxPage);
34+
const endIndex = Math.min(startIndex + (this.props.displayPages - 1), this.props.maxPage);
2335

2436
if (this.props.maxPage >= this.props.displayPages && (endIndex - startIndex) <= this.props.displayPages) {
2537
startIndex = endIndex - (this.props.displayPages - 1);
2638
}
2739

2840
for(let i = startIndex; i <= endIndex; i++){
29-
let thisButtonClasses = ClassNames('btn', 'btn-white', 'btn-sm', {
41+
const thisButtonClasses = ClassNames('btn', 'btn-white', 'btn-sm', {
3042
'label-success': this.props.currentPage === i
3143
});
3244
options.push(<button key={i} className={thisButtonClasses} data-value={i} onClick={this.pageChange}>{i}</button>);
@@ -57,32 +69,32 @@ export default class TabletablePager extends React.Component {
5769
// Custom methods
5870
//
5971

60-
pageChange(e) {
61-
e.stopPropagation();
72+
pageChange(e: SyntheticInputEvent) {
73+
e.preventDefault();
6274
this.props.onPageChange(parseInt(e.target.getAttribute('data-value')));
6375
}
6476

65-
previousPageChange(e) {
66-
e.stopPropagation();
77+
previousPageChange(e: SyntheticInputEvent) {
78+
e.preventDefault();
6779
if (this.props.currentPage > 1) {
6880
this.props.onPageChange(this.props.currentPage - 1);
6981
}
7082
}
7183

72-
nextPageChange(e) {
73-
e.stopPropagation();
84+
nextPageChange(e: SyntheticInputEvent) {
85+
e.preventDefault();
7486
if (this.props.currentPage < this.props.maxPage) {
7587
this.props.onPageChange(this.props.currentPage + 1);
7688
}
7789
}
7890

79-
firstPageChange(e) {
80-
e.stopPropagation();
91+
firstPageChange(e: SyntheticInputEvent) {
92+
e.preventDefault();
8193
this.props.onPageChange(1);
8294
}
8395

84-
lastPageChange(e) {
85-
e.stopPropagation();
96+
lastPageChange(e: SyntheticInputEvent) {
97+
e.preventDefault();
8698
this.props.onPageChange(this.props.maxPage);
8799
}
88100
}

0 commit comments

Comments
 (0)