data
to specify the data that you want to display on the table.
This prop is required and you should give it an array
// with es6
const data = [ ... ];
//...
<BootstrapTable data={ data }>
//...
</BootstrapTable>
keyField
to tell table which column is unique. This is same as isKey in <TableHeaderColumn>
Tips: react-bootstrap-table
support data manipulation(CRUD) so that we need to fetch correct row by a unique column.
<BootstrapTable data={ data } keyField='account'>
<TableHeaderColumn dataField='account'>Account</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Name</TableHeaderColumn>
</BootstrapTable>
As mentioned, following is equivalent
<BootstrapTable data={ data }>
<TableHeaderColumn isKey dataField='account'>Account</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Name</TableHeaderColumn>
</BootstrapTable>
react-bootstrap-table
default handle the data changing(like sorting, filtering insert or pagination etc) in a data store, call TableDataStore
.
So this prop is false
by default, if you enable remote
, which means you need to handle the all data manipulation on your application(flux
implement or something like that).
Therefore, react-bootstrap-table
support following event hooks so that you can interact to your server or local store with the data changing
onSortChange
onSearchChange
onPageChange
onSizePerPageList
onAddRow
onDeleteRow
onExportToCSV
onFilterChange
onCellEdit
remote(remoteObj) {
// Only cell editing, insert and delete row will be handled by remote store
remoteObj.cellEdit = true;
remoteObj.insertRow = true;
remoteObj.dropRow = true;
return remoteObj;
}
// ...
<BootstrapTable data={ data }>
<TableHeaderColumn isKey dataField='account'>Account</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Name</TableHeaderColumn>
</BootstrapTable>
To use remote pagination
properly you need to pass fetchInfo property.remote
mode.
height
to adjust the height of table. You need give a string with an unit(px) value like following:
Tips: react-bootstrap-table
display all the data without fixed header, because height is auto by default. If you give a height, the header will fixed when data is too long.
<BootstrapTable data={ data } height='120px'>
//...
</BootstrapTable>
maxHeight
to set the maximum height of table. You need give a string with an unit(px) value like height:
<BootstrapTable data={ data } maxHeight='120px'>
//...
</BootstrapTable>
<BootstrapTable data={ data } striped>
//...
</BootstrapTable>
<BootstrapTable data={ data } hover>
//...
</BootstrapTable>
<BootstrapTable data={ data } condensed>
//...
</BootstrapTable>
<BootstrapTable data={ data } bordered={ false }>
//...
</BootstrapTable>
pagination
to true, default is false.
Default pagination have a dropdown for choosing size per page and a pages list with next and previous page button
<BootstrapTable data={ data } pagination >
//...
</BootstrapTable>
Following is the default pagination view:
row
and rowIndex
as arguments and should return a string for the presenting class. for examples:
trClassFormat(row, rowIndex) {
// row is the current row data
return rowIndex % 2 === 0 ? "tr-odd" : "tr-even"; // return class name.
}
render() {
return (
<BootstrapTable data={ data } trClassName={ this.trClassFormat }>
//...
</BootstrapTable>
);
}
insertRow
to true, default is false.
react-bootstrap-table
support a row insert feature by a pop modal.
If you enable row insertion, there's a button on the upper left side of table.
<BootstrapTable data={ data } insertRow >
//...
</BootstrapTable>
Following is the pop modal for row insertion:
deleteRow
to true, default is false.
react-bootstrap-table
support a row deletion feature but you need to enable the row selection by selectRow
.Because react-bootstrap-table
will drop rows the according to the selected row by user select.
If you enable row dropping, there's a button on the upper left side of table.
render() {
const selectRow = {
mode: 'radio' //radio or checkbox
};
return (
<BootstrapTable
data={ data }
selectRow={ selectRow }
deleteRow>
//...
</BootstrapTable>
);
}
react-bootstrap-table
If enabled, there're input text fields per column under the table, user can input your filter condition by each column.
However, react-bootstrap-table
have a better column filter which have multiple filter type. You can check this
<BootstrapTable data={ data } columnFilter >
//...
</BootstrapTable>
search
to true, default is false.
If enabled, there is a input field on the upper left side of the table and user can type their search text on it.
<BootstrapTable data={ data } search >
//...
</BootstrapTable>
searchPlaceholder
to change the placeholder in search field, default is Search
<BootstrapTable
data={ data }
search
searchPlaceholder='input something...' >
//...
</BootstrapTable>
multiColumnSearch
, default is false.
If you want to use multi search, you must enable search
at first.
Tips: Use space to delimited search text. EX: 3 4, which means match all 3 or 4 datas in table.
<BootstrapTable
data={ data }
search
multiColumnSearch>
//...
</BootstrapTable>
exportCSV
as true, default is false.
If you enable, there's a button on the upper left side of table.
<BootstrapTable
data={ data }
exportCSV>
//...
</BootstrapTable>
<BootstrapTable
data={ data }
exportCSV
csvFileName='table-export'>
//...
</BootstrapTable>
<BootstrapTable
data={ data }
pagination
ignoreSinglePage>
//...
</BootstrapTable>
Top
and Bottom
<BootstrapTable
data={ data }
scrollTop={ 'Bottom' }>
//...
</BootstrapTable>
react-bs-table-container
class
<BootstrapTable
data={ data }
containerStyle={ { background: '#00ff00' } }>
//...
</BootstrapTable>
react-bs-table
class
<BootstrapTable
data={ data }
tableStyle={ { background: '#00ff00' } }>
//...
</BootstrapTable>
react-bs-container-header
class
<BootstrapTable
data={ data }
headerStyle={ { background: '#00ff00' } }>
//...
</BootstrapTable>
react-bs-container-body
class
<BootstrapTable
data={ data }
bodyStyle={ { background: '#00ff00' } }>
//...
</BootstrapTable>
react-bs-table-container
class
<BootstrapTable
data={ data }
containerClass='my-custom-class'>
//...
</BootstrapTable>
react-bs-table
class
<BootstrapTable
data={ data }
tableContainerClass='my-custom-class'>
//...
</BootstrapTable>
react-bs-container-header
class
<BootstrapTable
data={ data }
headerContainerClass='my-custom-class'>
//...
</BootstrapTable>
react-bs-container-body
class
<BootstrapTable
data={ data }
bodyContainerClass='my-custom-class'>
//...
</BootstrapTable>
react-bootstrap-table
separate two table
element as header and body. So the
tableHeaderClass
is for the table
element in the header.
<BootstrapTable
data={ data }
tableHeaderClass='my-custom-class'>
//...
</BootstrapTable>
react-bootstrap-table
separate two table
element as header and body. So the
tableBodyClass
is for the table
element in the body.
<BootstrapTable
data={ data }
tableBodyClass='my-custom-class'>
//...
</BootstrapTable>
<BootstrapTable
data={ data }
multiColumnSort={ 2 }>
//...
</BootstrapTable>
react-bootstrap-table
support the remote pagination feature, when you enable this feature,
react-bootstrap-table
will check fetchInfo to generate pagination.
fetchInfo
accept an object which have the following props:
render() {
const fetchInfo = {
dataTotalSize: 100 // or checkbox
};
return(
<BootstrapTable
data={ data }
remote={ true }
pagination={ true }
fetchInfo={ fetchInfo }>
//...
</BootstrapTable>
);
}
render() {
const fetchInfo = {
dataTotalSize: 100
};
return(
<BootstrapTable
data={ data }
remote={ true }
pagination={ true }
fetchInfo={ fetchInfo}>
//...
</BootstrapTable>
);
}
react-bootstrap-table
support the row selection feature, when you enable this feature,
react-bootstrap-table
will add a selection column at first position.
selectRow
accept an object which have the following props:
selectRow
, you should tell react-bootstrap-table
which the mode you wanted.
Following is a most simple example for configuring the selectRow
render() {
const selectRow = {
mode: 'radio' // or checkbox
};
return(
<BootstrapTable
data={ data }
selectRow={ selectRow }>
//...
</BootstrapTable>
);
}
radio
assigned, there's a radio button in the selection column; likewise, the checkbox
is same.
render() {
const selectRow = {
mode: 'radio' // single select
};
return(
<BootstrapTable
data={ data }
selectRow={ selectRow }>
//...
</BootstrapTable>
);
}
render() {
const selectRow = {
mode: 'checkbox' // multi select
};
return(
<BootstrapTable
data={ data }
selectRow={ selectRow }>
//...
</BootstrapTable>
);
}
render() {
const selectRow = {
mode: 'checkbox', // multi select
clickToSelect: true
};
return(
<BootstrapTable
data={ data }
selectRow={ selectRow }>
//...
</BootstrapTable>
);
}
render() {
const selectRow = {
mode: 'checkbox', // multi select
clickToSelectAndEditCell: true
};
return(
<BootstrapTable
data={ data }
selectRow={ selectRow }>
//...
</BootstrapTable>
);
}
isExpandableRow(row) {
if (row.id < 2) return true;
else return false;
}
expandComponent(row) {
return (
...
);
}
render() {
const selectRow = {
mode: 'checkbox',
clickToExpand: true // Trigger expand and selection together
};
return(
<BootstrapTable
data={ data }
expandableRow={ this.isExpandableRow }
expandComponent={ this.expandComponent }
selectRow={ selectRow }>
//...
</BootstrapTable>
);
}
bgColor
,
you will have more ability to custom rows background color when selecting.
render() {
const selectRow = {
mode: 'checkbox', // multi select
bgColor: '#fefefe'
};
return(
<BootstrapTable
data={ data }
selectRow={ selectRow }>
//...
</BootstrapTable>
);
}
render() {
const selectRow = {
mode: 'checkbox', // multi select
bgColor: function(row, isSelect) {
if (isSelect) {
const { id } = row;
if (id < 2) return 'blue';
else if (id < 4) return 'red';
else return 'yellow';
}
return null;
}
};
return(
<BootstrapTable
data={ data }
selectRow={ selectRow }>
//...
</BootstrapTable>
);
}
columnWidth
.
render() {
const selectRow = {
mode: 'checkbox', // multi select
columnWidth: '60px'
};
return(
<BootstrapTable
data={ data }
selectRow={ selectRow }>
//...
</BootstrapTable>
);
}
render() {
const selectRow = {
mode: 'checkbox', // multi select
className: 'custom-select-class'
};
return(
<BootstrapTable
data={ data }
selectRow={ selectRow }>
//...
</BootstrapTable>
);
}
render() {
const selectRow = {
mode: 'checkbox', // multi select
selected: [ 'row1', 'row3' ]
};
return(
<BootstrapTable
data={ data }
selectRow={ selectRow }>
//...
</BootstrapTable>
);
}
render() {
const selectRow = {
mode: 'checkbox', // multi select
unselectable: [ 'row4', 'row5' ]
};
return(
<BootstrapTable
data={ data }
selectRow={ selectRow }>
//...
</BootstrapTable>
);
}
render() {
const selectRow = {
mode: 'checkbox', // multi select
hideSelectColumn: true
};
return(
<BootstrapTable
data={ data }
selectRow={ selectRow }>
//...
</BootstrapTable>
);
}
render() {
const selectRow = {
mode: 'checkbox', // multi select
showOnlySelected: true
};
return(
<BootstrapTable
data={ data }
selectRow={ selectRow }>
//...
</BootstrapTable>
);
}
row
is the row data which you wanted to select or unselect.isSelected
is a boolean value which means "whether or not that row will be selected?".event
is the event target object.false
,
the select or deselect action will not be applied.
handleRowSelect(row, isSelected, e) {
// ...
}
render() {
const selectRow = {
mode: 'checkbox', // multi select
onSelect: this.handleRowSelect
};
return(
<BootstrapTable
data={ data }
selectRow={ selectRow }>
//...
</BootstrapTable>
);
}
isSelected
is a boolean value which means "whether or not that row will be selected?".rows
is the rows which be selected or unselected.
handleRowSelect(isSelected, rows) {
// ...
}
render() {
const selectRow = {
mode: 'checkbox', // multi select
onSelectAll: this.handleSelectAll
};
return(
<BootstrapTable
data={ data }
selectRow={ selectRow }>
//...
</BootstrapTable>
);
}
customComponent
, you can custom your own selection checkbox or radio button. This function take one argument: props
and have following properties:
react-bootstrap-table
support the cell editing feature, when you enable this feature,
react-bootstrap-table
will make the target cell as editable by clicking or dbclicking.
cellEdit
accept an object which have the following props:
Be carefully, when you enable cellEdit
, you should tell react-bootstrap-table
which the mode you wanted.
Following is a most simple example for configuring the cellEdit
render() {
const cellEdit = {
mode: 'click' // click cell to edit
};
return(
<BootstrapTable
data={ data }
cellEdit={ cellEdit }>
//...
</BootstrapTable>
);
}
click
or dbclick
)
render() {
const cellEdit = {
mode: 'click' // click cell to edit
};
return(
<BootstrapTable
data={ data }
cellEdit={ cellEdit }>
//...
</BootstrapTable>
);
}
render() {
const cellEdit = {
mode: 'dbclick' // double click cell to edit
};
return(
<BootstrapTable
data={ data }
cellEdit={ cellEdit }>
//...
</BootstrapTable>
);
}
blurToSave
will trigger a saving event on cell when mouse blur on the input field. Default is false.
In the default condition, you need to press ENTER
to save the cell.
render() {
const cellEdit = {
mode: 'click', // click cell to edit
blurToSave: true,
};
return(
<BootstrapTable
data={ data }
cellEdit={ cellEdit }>
//...
</BootstrapTable>
);
}
nonEditableRows
tell react-bootstrap-table
which rows should not be edited on all of the columns. Briefly, its a row level limitation
Please assign a callback function, and this function is supposed to be return an array of row keys.
render() {
const cellEdit = {
mode: 'click', // click cell to edit
nonEditableRows: : function() {
// if product id less than 3, will cause the whole row noneditable
// this function should return an array of row keys
return products.filter(p => p.id < 3).map(p => p.id);
}
};
return(
<BootstrapTable
data={ data }
cellEdit={ cellEdit }>
//...
</BootstrapTable>
);
}
beforeSaveCell(row, cellName, cellValue) {
// if you dont want to save this editing, just return false to cancel it.
}
render() {
const cellEdit = {
mode: 'click', // click cell to edit
beforeSaveCell: this.beforeSaveCell,
};
return(
<BootstrapTable
data={ data }
cellEdit={ cellEdit }>
//...
</BootstrapTable>
);
}
afterSaveCell(row, cellName, cellValue) {
// do your stuff...
}
render() {
const cellEdit = {
mode: 'click', // click cell to edit
afterSaveCell: this.afterSaveCell,
};
return(
<BootstrapTable
data={ data }
cellEdit={ cellEdit }>
//...
</BootstrapTable>
);
}
react-bootstrap-table
support a lotf of feature, you can configure some options for table.
options
accept an object which have the following props:Sort | Search | Pagination | Expanding Row | Customization | Others |
---|---|---|---|---|---|
|
constructor(props) {
super(props);
// Manage the sort state in your application
this.state = {
sortName: undefined,
sortOrder: undefined
};
this.onSortChange = this.onSortChange.bind(this);
}
onSortChange(sortName, sortOrder) {
this.setState({
sortName,
sortOrder
});
}
render() {
const options = {
sortName: this.state.sortName,
sortOrder: this.state.sortOrder,
onSortChange: this.onSortChange
};
return (
<BootstrapTable data={ products } options={ options }>
<TableHeaderColumn dataField='id' isKey={ true } dataSort={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' dataSort={ true }>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
desc
and asc
.
render() {
const options = {
defaultSortName: 'name'
};
return (
<BootstrapTable data={ products } options={ options }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' dataSort={ true }>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
desc
and asc
.
render() {
const options = {
defaultSortName: 'name',
defaultSortOrder: 'asc'
};
return (
<BootstrapTable data={ products } options={ options }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' dataSort={ true }>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
render() {
const options = {
sortIndicator: false
};
return (
<BootstrapTable data={ products } options={ options }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
sortName
sortOrder
onSortChange = (sortName, sortOrder) => {
// ...
}
render() {
const options = {
onSortChange: this.onSortChange
};
return (
<BootstrapTable data={ products } options={ options }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' dataSort>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price' dataSort>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
render() {
const options = {
noDataText: 'Empty Table'
};
return (
<BootstrapTable data={ products } options={ options }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
render() {
const options = {
withoutNoDataText: true
};
return (
<BootstrapTable data={ products } options={ options }>
// ...
</BootstrapTable>
);
}
render() {
const options = {
defaultSearch: 'Product 1'
};
return (
<BootstrapTable data={ products } options={ options } search>
// ...
</BootstrapTable>
);
}
render() {
const options = {
searchDelayTime: 1500
};
return (
<BootstrapTable data={ products } options={ options }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
editable
on <TableHeaderColumn>
when row insert.
render() {
const options = {
ignoreEditable: true
};
return (
<BootstrapTable data={ products } options={ options } insertRow>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
render() {
const options = {
clearSearch: true
};
return (
<BootstrapTable data={ products } options={ options } search>
// ...
</BootstrapTable>
);
}
searchText
colInfos
multiColumnSearch
searchText
.
This function almost used on remote, you can check
this example.
onSearchChange = (searchText, colInfos, multiColumnSearch) => {
//...
}
render() {
const options = {
onSearchChange: this.onSearchChange
};
return (
<BootstrapTable data={ products } options={ options } search>
// ...
</BootstrapTable>
);
}
searchText
result
afterSearch = (searchText, result) => {
//...
}
render() {
const options = {
afterSearch: this.afterSearch
};
return (
<BootstrapTable data={ products } options={ options } search>
// ...
</BootstrapTable>
);
}
handleTableComplete() {
// ...
}
render() {
const options = {
afterTableComplete: this.handleTableComplete
};
return (
<BootstrapTable data={ products } options={ options }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
rowKeys
, which means the row keys you dropped.
handleDeletedRow(rowKeys) {
// ...
}
render() {
const options = {
afterDeleteRow: this.handleDeletedRow
};
const selectRow = {
mode: 'checkbox',
clickToSelect: true
};
return (
<BootstrapTable
data={ products }
selectRow={ selectRow }
options={ options }
deleteRow>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
row
, which means the row object you added.
handleInsertedRow(row) {
// ...
}
render() {
const options = {
afterInsertRow: this.handleInsertedRow
};
return (
<BootstrapTable
data={ products }
options={ options }
insertRow>
// ...
</BootstrapTable>
);
}
filterConds
result
filterConds
: It's an array object which contain all column filter conditions.
result
: The results after filtering.
This function only work when you enable columnFilter
on <BootstrapTable>
or
define the filter
on <TableHeaderColumn>
afterColumnFilter(filterConds, result) {
console.log('Filter Conditions: ');
for (const prop in filterConds) {
console.log('Filter column= ' + prop + ', Filter value= ' + filterConds[prop]);
}
console.log('Result is:');
for (let i = 0; i < result.length; i++) {
console.log('Product: ' + result[i].id + ', ' + result[i].name + ', ' + result[i].price);
}
}
render() {
const options = {
afterColumnFilter: this.afterColumnFilter
};
return (
<BootstrapTable
data={ products }
options={ options }
columnFilter>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' filter={ { type: 'TextFilter', delay: 1000 } }>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
row
which presented as the new row data.
onAddRow
almost used on remote,
you can check this example.
onAddRow(row) {
// ...
}
render() {
const options = {
onAddRow: this.onAddRow
};
return (
<BootstrapTable
data={ products }
options={ options }
insertRow>
// ...
</BootstrapTable>
);
}
dataField
as object key and the value is the filter condition.
onFilterChange
almost used on remote,
you can check this example.
onFilterChange(filterObj) {
// ...
}
render() {
const options = {
onFilterChange: this.onFilterChange
};
return (
<BootstrapTable
data={ products }
options={ options }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' filter={ { type: 'TextFilter', delay: 1000 } }>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
onExportToCSV
almost used on remote,
you can check this example.
onExportToCSV(row) {
// ...
return products; // must return the data which you want to be exported
}
render() {
const options = {
onExportToCSV: this.onExportToCSV
};
return (
<BootstrapTable
data={ products }
options={ options }
exportCSV>
// ...
</BootstrapTable>
);
}
rows
which presented as the deleted rows.
onDeleteRow
almost used on remote,
you can check this example.
onDeleteRow(rows) {
// ...
}
render() {
const options = {
onDeleteRow: this.onDeleteRow
};
const selectRow = {
mode: 'checkbox'
}
return (
<BootstrapTable
data={ products }
options={ options }
selectRow= { selectRow }
deleteRow>
// ...
</BootstrapTable>
);
}
row
which is the row data which you click on.
onRowClick(row) {
// ...
}
render() {
const options = {
onRowClick: this.onRowClick
};
return (
<BootstrapTable
data={ products }
options={ options }>
// ...
</BootstrapTable>
);
}
row
which is the row data which you dbclick on.
onRowDoubleClick(row) {
// ...
}
render() {
const options = {
onRowDoubleClick: this.onRowDoubleClick
};
return (
<BootstrapTable
data={ products }
options={ options }>
// ...
</BootstrapTable>
);
}
onMouseEnter() {
// ...
}
render() {
const options = {
onMouseEnter: this.onMouseEnter
};
return (
<BootstrapTable
data={ products }
options={ options }>
// ...
</BootstrapTable>
);
}
onMouseLeave() {
// ...
}
render() {
const options = {
onMouseLeave: this.onMouseLeave
};
return (
<BootstrapTable
data={ products }
options={ options }>
// ...
</BootstrapTable>
);
}
row
is the row data which mouse over.
onRowMouseOver(row) {
// ...
}
render() {
const options = {
onRowMouseOver: this.onRowMouseOver
};
return (
<BootstrapTable
data={ products }
options={ options }>
// ...
</BootstrapTable>
);
}
row
is the row data which mouse out.
onRowMouseOut(row) {
// ...
}
render() {
const options = {
onRowMouseOut: this.onRowMouseOut
};
return (
<BootstrapTable
data={ products }
options={ options }>
// ...
</BootstrapTable>
);
}
next
rowKeys
next
: If you confirm to drop row, call next() to continue the process
rowKeys
: is the row keys which been deleted, you can call next function to apply this deletion.
customConfirm(next, dropRowKeys) {
const dropRowKeysStr = dropRowKeys.join(',');
if (confirm(`(It's a custom confirm)Are you sure you want to delete ${dropRowKeysStr}?`)) {
// If the confirmation is true, call the function that
// continues the deletion of the record.
next();
}
}
render() {
const options = {
handleConfirmDeleteRow: this.customConfirm
};
const selectRow = {
mode: 'checkbox',
clickToSelect: true
};
return (
<BootstrapTable
data={ products }
selectRow={ selectRow }
options={ options }
deleteRow>
// ...
</BootstrapTable>
);
}
jobStatusValidator(value) {
const nan = isNaN(parseInt(value, 10));
if (nan) {
return 'Job Status must be a integer!';
}
return true;
}
render() {
const options = {
beforeShowError: (type, msg) => {
this.setState({
errType: type,
errMsg: msg
});
// return false or do not return will not trigger the toastr,
// if you want the toastr popup, you should return true always.
}
};
const cellEditProp = {
mode: 'click',
blurToSave: true
};
return (
<p style={ { color: 'red' } }>{ `[${this.state.errType}]: ${this.state.errMsg}` }</p>
<BootstrapTable
data={ products }
cellEdit={ cellEditProp }
options={ options }>
<TableHeaderColumn dataField='id' isKey={ true }>Job ID</TableHeaderColumn>
<TableHeaderColumn dataField='status' editable={ { validator: this.jobStatusValidator } }>Job Status</TableHeaderColumn>
</BootstrapTable>
);
}
true
, you can disable to print the toolbar via false
render() {
const options = {
printToolBar: false
};
return (
<BootstrapTable
data={ products }
options={ options }>
<TableHeaderColumn dataField='id' isKey>Job ID</TableHeaderColumn>
<TableHeaderColumn dataField='status'>Job Status</TableHeaderColumn>
</BootstrapTable>
);
}
render() {
const options = {
prePage: 'Previous'
};
return (
<BootstrapTable
data={ products }
options={ options }
pagination>
// ...
</BootstrapTable>
);
}
render() {
const options = {
nextPage: 'Next'
};
return (
<BootstrapTable
data={ products }
options={ options }
pagination>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
render() {
const options = {
firstPage: 'First Page'
};
return (
<BootstrapTable
data={ products }
options={ options }
pagination>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
render() {
const options = {
lastPage: 'Last Page'
};
return (
<BootstrapTable
data={ products }
options={ options }
pagination>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
render() {
const options = {
page: 3 // Showing page 3 as default
};
return (
<BootstrapTable
data={ products }
options={ options }
pagination>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
10
, 25
, 30
, 50
.
render() {
const options = {
sizePerPageList: [ 5, 15, 30 ]
};
return (
<BootstrapTable
data={ products }
options={ options }
pagination>
// ...
</BootstrapTable>
);
}
However, you can do more customization like following:
render() {
const options = {
sizePerPageList: [ {
text: '5', value: 5
}, {
text: '10', value: 10
}, {
text: 'All', value: products.length
} ]
};
return (
<BootstrapTable
data={ products }
options={ options }
pagination>
// ...
</BootstrapTable>
);
}
render() {
const options = {
sizePerPage: 30 // Showing 30 for the size per page as default
};
return (
<BootstrapTable
data={ products }
options={ options }
pagination>
// ...
</BootstrapTable>
);
}
render() {
const options = {
paginationSize: 3
};
return (
<BootstrapTable
data={ products }
options={ options }
pagination>
// ...
</BootstrapTable>
);
}
render() {
const options = {
hideSizePerPage: true
};
return (
<BootstrapTable
data={ products }
options={ options }
pagination>
// ...
</BootstrapTable>
);
}
start
: Current start index.
to
: Current end index.
total
: The total data volume.
render() {
const options = {
paginationShowsTotal: true // Enable showing total text
};
return (
<BootstrapTable
data={ products }
options={ options }
pagination>
// ...
</BootstrapTable>
);
}
Following is a customization example
renderPaginationShowsTotal(start, to, total) {
return (
<p style={ { color: 'blue' } }>
From { start } to { to }, totals is { total } (its a customize text)
</p>
);
}
render() {
const options = {
paginationShowsTotal: this.renderPaginationShowsTotal // custom
};
return (
<BootstrapTable
data={ products }
options={ options }
pagination>
// ...
</BootstrapTable>
);
}
render() {
const options = {
pageStartIndex: 0
};
return (
<BootstrapTable
data={ products }
options={ options }
pagination>
// ...
</BootstrapTable>
);
}
onPageChange = (page, sizePerPage) => {
// ...
}
render() {
const options = {
onPageChange: this.onPageChange
};
return (
<BootstrapTable
data={ products }
options={ options }
pagination>
// ...
</BootstrapTable>
);
}
onSizePerPageList = (sizePerPage) => {
// ...
}
render() {
const options = {
onSizePerPageList: this.onSizePerPageList
};
return (
<BootstrapTable
data={ products }
options={ options }
pagination>
// ...
</BootstrapTable>
);
}
false
, if true
assign, the pagination list will be hide totalliy if only one page.
render() {
const options = {
hidePageListOnlyOnePage: true
};
return (
<BootstrapTable
data={ products }
options={ options }
pagination>
// ...
</BootstrapTable>
);
}
expandComponent(row) {
return (
...
);
}
render() {
const options = {
expandRowBgColor: 'rgb(242, 255, 163)'
};
return (
<BootstrapTable
data={ products }
options= { options }
expandableRow={ () => { return true; } }
expandComponent={ this.expandComponent }>
// ...
</BootstrapTable>
);
}
react-bootstrap-table
how to trigger expanding by clicking on row
or column
level.
It value is column
, default all the columns are expandable, if you want some column as unexpandable, check expandable.
expandComponent(row) {
return (
...
);
}
render() {
const options = {
expandBy: 'column' // Currently, available value is row and column, default is row
};
return (
<BootstrapTable
data={ products }
options= { options }
expandableRow={ () => { return true; } }
expandComponent={ this.expandComponent }>
// ...
</BootstrapTable>
);
}
render() {
const options = {
insertText: 'Custom Insert Text'
};
return (
<BootstrapTable
data={ products }
options={ options }
insertRow>
// ...
</BootstrapTable>
);
}
render() {
const options = {
deleteText: 'Custom Delete Text'
};
return (
<BootstrapTable
data={ products }
options={ options }
deleteRow>
// ...
</BootstrapTable>
);
}
render() {
const options = {
saveText: 'Custom Save Text'
};
return (
<BootstrapTable
data={ products }
options={ options }
insertRow>
// ...
</BootstrapTable>
);
}
render() {
const options = {
closeText: 'Custom Close Text'
};
return (
<BootstrapTable
data={ products }
options={ options }
insertRow>
// ...
</BootstrapTable>
);
}
render() {
const options = {
exportCSVText: 'Custom Export CSV Text'
};
return (
<BootstrapTable
data={ products }
options={ options }
exportCSV>
// ...
</BootstrapTable>
);
}
react-bootstrap-table
which rows are able to expand. This props accept a callback function and is suppose to be return an Array of row keys
expandableRow
always used with expandComponent, both of props are enable the expand row functionality on table.
isExpandableRow(row) {
if (row.id < 2) return true;
else return false;
}
expandComponent(row) {
return (
...
);
}
render() {
return (
<BootstrapTable
data={ products }
expandableRow={ this.isExpandableRow }
expandComponent={ this.expandComponent }>
// ...
</BootstrapTable>
);
}
react-bootstrap-table
what's content should be rendered in the expanding content. This props accept a callback function and is suppose to be return JSX or String
expandComponent
always used with expandableRow, both of props are enable the expand row functionality on table.
isExpandableRow(row) {
if (row.id < 2) return true;
else return false;
}
expandComponent(row) {
return (
...
);
}
render() {
return (
<BootstrapTable
data={ products }
expandableRow={ this.isExpandableRow }
expandComponent={ this.expandComponent }>
// ...
</BootstrapTable>
);
}
expandColumnOptions
only have four available property currently.
expandColumnVisible
: will enable an indicator column at first column if true
. Default is false
.expandColumnComponent
: a callback function for custom the indicator column.columnWidth
: set the width of indicator column.expandColumnBeforeSelectColumn
: default is true, false
will move the expand indicator column after selection column.
isExpandableRow(row) {
if (row.id < 2) return true;
else return false;
}
expandComponent(row) {
return (
...
);
}
expandColumnComponent({ isExpandableRow, isExpanded }) {
let content = '';
if (isExpandableRow) {
content = (isExpanded ? '(-)' : '(+)' );
} else {
content = ' ';
}
return (
<div> { content } </div>
);
}
render() {
return (
<BootstrapTable
data={ products }
expandableRow={ this.isExpandableRow }
expandComponent={ this.expandComponent }
expandColumnOptions={ {
expandColumnVisible: true,
expandColumnComponent: this.expandColumnComponent,
columnWidth: 50
} }>
// ...
</BootstrapTable>
);
}
handleAddRow
to insert an new row to table.
var fakeRow = {
id: 10,
name: 'Product one',
price: 240
};
// insert a new row
var result = this.refs.table.handleAddRow(fakeRow); // this.refs.table is a ref for BootstrapTable
if (result){ // some error happen, ex: doesn't assign row key or row key duplicated
console.log(result);
}
handleAddRowAtBegin
to insert an new row as first row on table.
var fakeRow = {
id: 10,
name: 'Product one',
price: 240
};
// insert a new row
var result = this.refs.table.handleAddRowAtBegin(fakeRow); // this.refs.table is a ref for BootstrapTable
if (result){ // some error happen, ex: doesn't assign row key or row key duplicated
console.log(result);
}
handleDropRow
to drop rows in table.
// Drop row key 2 & 3
this.refs.table.handleDropRow([ 2, 3 ]); // this.refs.table is a ref for BootstrapTable
handleFilterData
to do column filtering on table.
// find name eq 'Allen' && age eq 26
this.refs.table.handleFilterData({ // this.refs.table is a ref for BootstrapTable
name: "Allen",
age: 26
});
handleSearch
with search text for fully searching.
// Search table for 'React.js'
this.refs.table.handleSearch('React.js'); // this.refs.table is a ref for BootstrapTable
handleSort
with order and field for sorting.
// Force a sort for product_id field by desc
this.refs.table.handleSort('desc', 'product_id'); // this.refs.table is a ref for BootstrapTable
getPageByRowKey
to get the page by a rowkey.
// Find the page of product_id
this.refs.table.getPageByRowKey('product_id'); // this.refs.table is a ref for BootstrapTable
handleExportCSV
to export table as csv.
// export CSV file
this.refs.table.handleExportCSV(); // this.refs.table is a ref for BootstrapTable
cleanSelected
deselect all rows.
this.refs.table.cleanSelected(); // this.refs.table is a ref for BootstrapTable
reset
to clean all the status on the table currently.
this.refs.table.reset(); // this.refs.table is a ref for BootstrapTable
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
isKey
to tell table which column is unique. This is same as keyField in <BootstrapTable>
Tips: You need choose one of configuration to set the key field: isKey
or keyField
in <BootstrapTable>
.
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' width='150px'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price' width='20%'>Product Price</TableHeaderColumn>
</BootstrapTable>
left
, center
, right
, start
and end
.
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' dataAlign='right'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
left
, center
, right
, start
and end
.
Tips: If you don't set the headerAlign
, default will follow dataAlign
.
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' headerAlign='right'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' dataSort>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price' dataSort>Product Price</TableHeaderColumn>
</BootstrapTable>
direction
which present the sort order currently.
fieldName
is the on sorting field name.
renderCaret = (direction, fieldName) => {
if (direction === 'asc') {
return (
up
);
}
if (direction === 'desc') {
return (
down
);
}
return (
up/down
);
}
render() {
return (
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' dataSort caretRender={ this.renderCaret }>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
cell
row
formatExtraData
rowIdx
formatExtraData
will be the value which you assign it on <TableHeaderColumn>
.
You need to return a String or JSX in dataFormat
priceFormatter(cell, row) { // String example
return `<i class='glyphicon glyphicon-usd'></i> ${cell}`;
}
render() {
return (
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price' dataFormat={ this.priceFormatter }>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
priceFormatter(cell, row) { // JSX example
return ( ... );
}
render() {
return (
<BootstrapTable data={ products } search>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price' dataFormat={ this.priceFormatter }>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
enumFormatter(cell, row, enumObject) {
return enumObject[cell];
}
render() {
const qualityType = {
0: 'good',
1: 'bad',
2: 'unknown'
};
const inStockStatus = {
1: 'yes',
2: 'no'
};
return (
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='quality' dataFormat={ enumFormatter } formatExtraData={ qualityType }>Product Quality</TableHeaderColumn>
<TableHeaderColumn dataField='inStock' dataFormat={ enumFormatter } formatExtraData={ inStockStatus }>Product Stock Status</TableHeaderColumn>
</BootstrapTable>
);
}
<BootstrapTable data={ products } search>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' tdAttr={ { 'data-attr': 'test' } }>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
<BootstrapTable data={ products } search>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' tdStyle={ { whiteSpace: 'normal' } }>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
<BootstrapTable data={ products } search>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' thStyle={ { 'fontWeight': 'lighter' } }>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
<BootstrapTable data={ products } search>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' filterFormatted>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price' filter={ { type: 'TextFilter' } }>Product Price</TableHeaderColumn>
</BootstrapTable>
cell
row
csvFormat
, you should return a string.
csvFormatter(cell, row) {
return `${row.id}: ${cell} USD`;
}
render() {
return (
<BootstrapTable data={ products } exportCSV>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price' csvFormat={ this.csvFormatter }>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
<BootstrapTable data={ products } exportCSV>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' csvHeader='product-name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
csvFormat
function.
csvPriceFormatter(cell, row) {
return `${row.id}: ${cell} USD`;
}
csvQualityFormatter(cell, row, extra) {
return extra[cell];
}
//...
<BootstrapTable data={ products } exportCSV>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' csvHeader='product-name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
<TableHeaderColumn dataField='quality' csvFormat={ this.csvQualityFormatter } csvFormatExtraData={ qualityType }>Product Quality</TableHeaderColumn>
</BootstrapTable>
export={true}
usually be used when you want to export a column which is hidden. Because hidden column can't be export to csv by default.
export={false}
to tell the react-bootstrap-table
do not export this column when exporting csv.
<BootstrapTable data={ products } exportCSV>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' export hidden>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
column
level.. You can assign which columns are expandable or not by expandable
.
For example, following we disable Product Name and Product Price as unexpandable, so use click on this both column will not trigger expanding row.
expandComponent(row) {
return (
...
);
}
render() {
const options = {
expandBy: 'column' // Currently, available value is row and column, default is row
};
return (
<BootstrapTable
data={ products }
options= { options }
expandableRow={ () => { return true; } }
expandComponent={ this.expandComponent }>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' expandable={ false }>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price' expandable={ false }>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
<BootstrapTable data={ products } keyField='id' insertRow>
<TableHeaderColumn dataField='id' autoValue>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
<BootstrapTable data={ products } search>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' searchable={ false }>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
title
on each column, default is false.
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' columnTitle>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price' columnTitle>Product Price</TableHeaderColumn>
</BootstrapTable>
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' headerTitle={ false }>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
TableHeaderColumn
is a JSX or Object, we prefer to add this prop to describe this column with a pure text(String).
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' headerText='Product Name'>{ this.renderProductNameContent }</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
a
b
order
sortField
extraData
extraData
is the data from the sortFuncExtraData.
Tips: This function should return a negative, zero, or positive value, depending on the arguments.
revertSortFunc(a, b, order) { // order is desc or asc
if (order === 'desc') {
return a.price - b.price;
} else {
return b.price - a.price;
}
}
render() {
return (
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price' dataSort sortFunc={ this.revertSortFunc }>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
String
or Function
.
If a Function
given, you should return a String which is the class name you want to add on.
customHeaderClass() {
return 'custom-header-class';
}
render() {
return (
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price' className={ this.customHeaderClass }>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
String
or Function
.
If Function
, it taking four arguments:
cell
row
rowIndex
columnIndex
columnClassNameFormat(fieldValue, row, rowIdx, colIdx) {
// fieldValue is column value
// row is whole row object
// rowIdx is index of row
// colIdx is index of column
return rowIdx % 2 === 0 ? 'td-column-function-even-example' : 'td-column-function-odd-example';
}
render() {
return (
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price' columnClassName={ this.columnClassNameFormat }>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
render() {
const cellEditProps = {
mode: 'click'
};
return (
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price' editColumnClassName='class-for-editing-cell'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
priceValidator = (value) => {
const nan = isNaN(parseInt(value, 10));
if (nan) {
return 'Product price must be a integer!';
}
return true;
}
invalidPrice = (cell, row) => {
console.log(`${cell} at row id: ${row.id} fails on editing`);
return 'invalid-price-class';
}
render() {
const cellEditProps = {
mode: 'click'
};
return (
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price' editable={ { validator: priceValidator } } invalidEditColumnClassName={ this.invalidPrice }>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
Function
given, you have ability to control the editable level on cell instead of column level. For this callback function, you are
supposed to be return a bool value to decide this cell editable or not and this callback accept four argument, cell
, row
, rowIndex
, columnIndex
.
If Object
, you can give more customization on editing cell. This object have following properties:
type
: what edit type on editing cell, available values are textarea
, select
, checkbox
, and datetime
readOnly
: Default is false
, true
will make cell can't be edited but still can be insert.validator
: give a callback function for validation which takes "cellValue" and "row" as arguments. This function should return a boolean or object value.
options.values
: options.values means the data in select or checkbox. If checkbox, use a ':' (colon) to separate the values, e.g. Y:N.
render() {
const cellEdit = {
mode: 'click',
blurToSave: true
};
return (
<BootstrapTable data={ products } cellEdit={ cellEdit }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price' editable={ false }>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
jobNameValidator(value, row) {
// If this function return an object, you got some ability to customize your error message
const response = { isValid: true, notification: { type: 'success', msg: '', title: '' } };
if (!value) {
response.isValid = false;
response.notification.type = 'error';
response.notification.msg = 'Value must be inserted';
response.notification.title = 'Requested Value';
} else if (value.length < 10) {
response.isValid = false;
response.notification.type = 'error';
response.notification.msg = 'Value must have 10+ characters';
response.notification.title = 'Invalid Value';
}
return response;
}
jobStatusValidator(value, row) {
const nan = isNaN(parseInt(value, 10));
if (nan) {
return 'Job Status must be a integer!';
}
return true;
}
render() {
const cellEdit = {
mode: 'click',
blurToSave: true
};
return (
<BootstrapTable data={ products } cellEdit={ cellEdit }>
<TableHeaderColumn dataField='id' isKey={ true }>Job ID</TableHeaderColumn>
<TableHeaderColumn dataField='status' editable={ { validator: jobStatusValidator } }>Job Status</TableHeaderColumn>
<TableHeaderColumn dataField='name' editable={ { type: 'textarea', validator: jobNameValidator } }>Job Name</TableHeaderColumn>
<TableHeaderColumn dataField='type' editable={ { type: 'select', options: { values: jobTypes } } }>Job Type</TableHeaderColumn>
<TableHeaderColumn dataField='active' editable={ { type: 'checkbox', options: { values: 'Y:N' } } }>Active</TableHeaderColumn>
</BootstrapTable>
);
}
getElement
(REQUIRED): Accept a callback function and take two arguments: onUpdate
and props
.
customEditorParameters
: Another extra data for custom cell edit component.
This is a good example for showing how to use custom cell editing.
rowspan
and colSpan
. Following is a simple example for group header.
render() {
return (
<BootstrapTable data={ products }>
<TableHeaderColumn row='0' rowSpan='2' dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn row='0' colSpan='2'>Product</TableHeaderColumn>
<TableHeaderColumn row='1' dataField='name'>Name</TableHeaderColumn>
<TableHeaderColumn row='1' dataField='price'>Price</TableHeaderColumn>
</BootstrapTable>
);
}
filter
:
1. type
: Available value is TextFilter
, SelectFilter
, NumberFilter
, DateFilter
, RegexFilter
, YOUR_CUSTOM_FILTER
(Custom Example)
2. defaultValue
: Default value on filter.
If type is NumberFilter
, the default value will be like { number: xxx, comparator: '>' }
If type is DateFilter
, the default value will be like { date: xxx, comparator: '>' }
3. condition
: Default is eq
, you can change to like
to search for a specified pattern. This only work for TextFilter
, SelectFilter
4. delay
: Assign a millisecond for delay when trigger filtering, default is 500.
5. placeholder
: Assign the placeholder text on all the filter.
6. numberComparators
: Only work on NumberFilter
and DateFilter
. Accept an array which conatin the filter condition, like: ['<','>','=']
7. options
: Only work on SelectFilter
or NumberFilter
:
SelectFilter
: you can assign the selection options by an Object
which presented as { 0: 'good', 1: 'bad' ... }
NumberFilter
: you can assign a number range by an array which presented as [1,2,3,4...]
cleanNameFilter = () => {
this.refs.name.cleanFiltered(); // this.refs.name is the reference to name column
}
render() {
return (
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn>
<TableHeaderColumn ref='name' dataField='name' filter={ { type: 'TextFilter', delay: 1000 } }>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}