Skip to content

Commit c7758d6

Browse files
committed
add #604 example
1 parent ad8294f commit c7758d6

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

examples/js/column-format/demo.js

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React from 'react';
33
import HtmlColumnFormatTable from './html-column-format-table';
44
import ReactColumnFormatTable from './react-column-format-table';
55
import ExtraDataColumnFormatTable from './extra-data-column-format-table';
6+
import GetRowIndexTable from './get-row-index-table';
67

78
class Demo extends React.Component {
89
render() {
@@ -35,6 +36,16 @@ class Demo extends React.Component {
3536
</div>
3637
</div>
3738
</div>
39+
<div className='col-md-offset-1 col-md-8'>
40+
<div className='panel panel-default'>
41+
<div className='panel-heading'>Get Row Index Example</div>
42+
<h5><b>Use the <code>fourth</code> argument to get the row index</b>. Check the browser console</h5>
43+
<div className='panel-body'>
44+
<h5>Source in /examples/js/column-format/get-row-index-table.js</h5>
45+
<GetRowIndexTable />
46+
</div>
47+
</div>
48+
</div>
3849
</div>
3950
);
4051
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* eslint max-len: 0 */
2+
/* eslint no-unused-vars: 0*/
3+
import React from 'react';
4+
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
5+
6+
7+
const jobs = [];
8+
9+
function addProducts(quantity) {
10+
const startId = jobs.length;
11+
for (let i = 0; i < quantity; i++) {
12+
const id = startId + i;
13+
jobs.push({
14+
id: id,
15+
name: 'Application_Name_ ' + id,
16+
active: i % 2 === 0 ? true : false
17+
});
18+
}
19+
}
20+
21+
addProducts(5);
22+
23+
24+
class ActiveFormatter extends React.Component {
25+
render() {
26+
return (
27+
<input type='checkbox' checked={ this.props.active }/>
28+
);
29+
}
30+
}
31+
32+
function activeFormatter(cell, row, enumObject, index) {
33+
console.log(`The row index: ${index}`);
34+
return (
35+
<ActiveFormatter active={ cell } />
36+
);
37+
}
38+
39+
export default class GetRowIndexTable extends React.Component {
40+
render() {
41+
return (
42+
<BootstrapTable data={ jobs }>
43+
<TableHeaderColumn dataField='id' isKey={ true }>Job ID</TableHeaderColumn>
44+
<TableHeaderColumn dataField='name'>Job Name</TableHeaderColumn>
45+
<TableHeaderColumn dataField='active' dataFormat={ activeFormatter }>Active</TableHeaderColumn>
46+
</BootstrapTable>
47+
);
48+
}
49+
}

0 commit comments

Comments
 (0)