Skip to content

Commit dc28464

Browse files
committed
example for #990
1 parent e219cef commit dc28464

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

examples/js/remote/demo.js

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import RemoteStoreInsertRow from './remote-store-insert-row';
77
import RemoteStoreDeleteRow from './remote-store-delete-row';
88
import RemoteStoreCellEdit from './remote-store-cell-edit';
99
import RemoteStoreExportCSV from './remote-store-export-csv';
10+
import RemoteStoreAlternative from './remote-store-alternative';
1011
import RemoteStoreAll from './remote-store-all';
1112

1213
class Demo extends React.Component {
@@ -93,6 +94,17 @@ class Demo extends React.Component {
9394
</div>
9495
</div>
9596
</div>
97+
<div className='col-md-offset-1 col-md-8'>
98+
<div className='panel panel-default'>
99+
<div className='panel-heading'>Alternative Configure Remote Example</div>
100+
<div className='panel-body'>
101+
<h5>Source in /examples/js/remote/remote-store-alternative.js and
102+
/examples/js/remote/remote-alternative.js</h5>
103+
<span>Remote mode also allow you to choose which functionality should be handle by remote.</span>
104+
<RemoteStoreAlternative />
105+
</div>
106+
</div>
107+
</div>
96108
<div className='col-md-offset-1 col-md-8'>
97109
<div className='panel panel-default'>
98110
<div className='panel-heading'>Remote All Features Together Example</div>
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react';
2+
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
3+
4+
export default class RemoteAlternative extends React.Component {
5+
constructor(props) {
6+
super(props);
7+
}
8+
9+
remote(remoteObj) {
10+
// Only cell editing, insert and delete row will be handled by remote store
11+
remoteObj.cellEdit = true;
12+
remoteObj.insertRow = true;
13+
remoteObj.dropRow = true;
14+
return remoteObj;
15+
}
16+
17+
render() {
18+
const cellEditProp = {
19+
mode: 'click'
20+
};
21+
const selectRow = {
22+
mode: 'checkbox',
23+
cliclToSelct: true
24+
};
25+
return (
26+
<BootstrapTable data={ this.props.data }
27+
selectRow={ selectRow }
28+
remote={ this.remote }
29+
insertRow deleteRow search pagination
30+
cellEdit={ cellEditProp }
31+
options={ {
32+
onCellEdit: this.props.onCellEdit,
33+
onDeleteRow: this.props.onDeleteRow,
34+
onAddRow: this.props.onAddRow
35+
} }>
36+
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
37+
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
38+
<TableHeaderColumn dataField='price' dataSort>Product Price</TableHeaderColumn>
39+
</BootstrapTable>
40+
);
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React from 'react';
2+
import RemoteAlternative from './remote-alternative';
3+
4+
function getProducts() {
5+
const products = [];
6+
const startId = products.length;
7+
for (let i = 0; i < 12; i++) {
8+
const id = startId + i;
9+
products.push({
10+
id: id,
11+
name: 'Item name ' + id,
12+
price: Math.floor((Math.random() * 2000) + 1)
13+
});
14+
}
15+
return products;
16+
}
17+
18+
export default class RemoteStoreAlternative extends React.Component {
19+
constructor(props) {
20+
super(props);
21+
this.products = getProducts();
22+
this.state = {
23+
data: this.products
24+
};
25+
}
26+
27+
onCellEdit = (row, fieldName, value) => {
28+
const { data } = this.state;
29+
let rowIdx;
30+
const targetRow = data.find((prod, i) => {
31+
if (prod.id === row.id) {
32+
rowIdx = i;
33+
return true;
34+
}
35+
return false;
36+
});
37+
if (targetRow) {
38+
targetRow[fieldName] = value;
39+
data[rowIdx] = targetRow;
40+
this.setState({ data });
41+
}
42+
}
43+
44+
onAddRow = (row) => {
45+
this.products.push(row);
46+
this.setState({
47+
data: this.products
48+
});
49+
}
50+
51+
onDeleteRow = (row) => {
52+
this.products = this.products.filter((product) => {
53+
return product.id !== row[0];
54+
});
55+
56+
this.setState({
57+
data: this.products
58+
});
59+
}
60+
61+
render() {
62+
return (
63+
<RemoteAlternative
64+
onCellEdit={ this.onCellEdit }
65+
onAddRow={ this.onAddRow }
66+
onDeleteRow={ this.onDeleteRow }
67+
{ ...this.state } />
68+
);
69+
}
70+
}

0 commit comments

Comments
 (0)