There are two simple way to custom your column
dataFormat
and return a String
// with es6
function priceFormatter(cell, row) {
return ` ${cell}`;
}
//...
<TableHeaderColumn dataField='price' dataFormat={priceFormatter}>Price</TableHeaderColumn>
dataFormat
and return a JSX
// with es6
function priceFormatter(cell, row) {
return (<div>....</div>);
}
//...
<TableHeaderColumn dataField='price' dataFormat={priceFormatter}>Price</TableHeaderColumn>
ToolBar
is the area on the top of table, it contain the search panel, buttons for data manipulation.
After v3.0.0
, you can custom all the components in the ToolBar also itself too. In
this section, only the ToolBar itself will be introduced.
Give a toolBar
in options
props and toolBar
only accept a function and a JSX returned value is necessary
createCustomToolBar = props => {
/**
* This function only pass one argument, is props object which has following properties
*
* {
* components: { // here are all the components
* exportCSVBtn, // export CSV button JSX
* insertBtn, // insert button JSX
* deleteBtn, // delete button JSX
* showSelectedOnlyBtn, // show selected button JSX
* searchPanel, // search panel JSX
* btnGroup, // button groups JSX
* searchField, // search field JSX
* clearBtn // clear search field JSX
* },
* event: { // here are all the related event you may use it
* openInsertModal, // call it to open insert modal
* closeInsertModal, // call it to close insert modal
* dropRow, // call it to drop row
* showOnlyToogle, // call it to toogle show only selections
* exportCSV, // call it to export CSV file
* search // call it with search text to search table
* }
* }
*
**/
return (
<div style={ { margin: '15px' } }>
{ props.components.btnGroup }
<div className='col-xs-8 col-sm-4 col-md-4 col-lg-2'>
{ props.components.searchPanel }
</div>
</div>
);
}
// ...
const options = {
toolBar: this.createCustomToolBar
};
// ...
<BootstrapTable data={rows} options={options}>
btn-group
class in bootstrap. This is a chance that you can custom this button group.
Give a btnGroup
in options
props and btnGroup
only accept a function and a JSX returned value is necessary
createCustomButtonGroup = props => {
/**
* This function only pass one argument, is props object has following properties
* {
* exportCSVBtn, // export CSV button JSX
* insertBtn, // insert button JSX
* deleteBtn, // delete button JSX
* showSelectedOnlyBtn // show selected button JSX
* }
***/
return (
...
);
}
// ...
const options = {
btnGroup: this.createCustomButtonGroup
};
// ...
<BootstrapTable data={rows} options={options}>
insertBtn
in options
props,
insertBtn
only accept a function and a JSX returned value is necessary. This function will take one argument: onClick
.
Following, we have two way to customize the insert button:
InsertButton
by defaultInsertButton
is a exported React component by
react-bootstrap-table
, and it have following props you can configure:
import { BootstrapTable, TableHeaderColumn, InsertButton } from 'react-bootstrap-table';
// ...
handleInsertButtonClick = (onClick) => {
// Custom your onClick event here,
// it's not necessary to implement this function if you have no any process before onClick
console.log('This is my custom function for InserButton click event');
onClick();
}
createCustomInsertButton = (onClick) => {
return (
<InsertButton
btnText='CustomInsertText'
btnContextual='btn-warning'
className='my-custom-class'
btnGlyphicon='glyphicon-edit'
onClick={ () => this.handleInsertButtonClick(onClick) }/>
);
}
//...
const options = {
insertBtn: this.createCustomInsertButton
};
//...
<BootstrapTable data={rows} options={options} insertRow>
InsertButton
is not satisfied to your requirement, you can custom a new one as following
createCustomInsertButton = (onClick) => {
return (
<button style={ { color: 'red' } } onClick={ onClick }>Add rows</button>
);
}
//...
const options = {
insertBtn: this.createCustomInsertButton
};
//...
<BootstrapTable data={rows} options={options} insertRow>
deleteBtn
in options
props,
deleteBtn
only accept a function and a JSX returned value is necessary. This function will take one argument: onClick
.
Following, we have two way to customize the delete row button:
DeleteButton
by defaultDeleteButton
is a exported React component by
react-bootstrap-table
, and it have following props you can configure:
import { BootstrapTable, TableHeaderColumn, DeleteButton } from 'react-bootstrap-table';
// ...
handleDeleteButtonClick = (onClick) => {
// Custom your onClick event here,
// it's not necessary to implement this function if you have no any process before onClick
console.log('This is my custom function for DeleteButton click event');
onClick();
}
createCustomDeleteButton = (onClick) => {
return (
<DeleteButton
btnText='CustomDeleteText'
btnContextual='btn-warning'
className='my-custom-class'
btnGlyphicon='glyphicon-edit'
onClick={ () => this.handleDeleteButtonClick(onClick) }/>
);
}
//...
const options = {
deleteBtn: this.createCustomDeleteButton
};
//...
<BootstrapTable data={rows} options={options} deleteRow>
DeleteButton
is not satisfied to your requirement, you can custom a new one as following
createCustomDeleteButton = (onClick) => {
return (
<button style={ { color: 'red' } } onClick={ onClick }>Delete rows</button>
);
}
//...
const options = {
deleteBtn: this.createCustomDeleteButton
};
//...
<BootstrapTable data={rows} options={options} deleteRow>
exportCSVBtn
in options
props,
exportCSVBtn
only accept a function and a JSX returned value is necessary. This function will take one argument: onClick
.
Following, we have two way to customize the export csv button:
ExportCSVButton
by defaultExportCSVButton
is a exported React component by
react-bootstrap-table
, and it have following props you can configure:
import { BootstrapTable, TableHeaderColumn, ExportCSVButton } from 'react-bootstrap-table';
// ...
handleExportCSVButtonClick = (onClick) => {
// Custom your onClick event here,
// it's not necessary to implement this function if you have no any process before onClick
console.log('This is my custom function for ExportCSVButton click event');
onClick();
}
createCustomExportCSVButton = (onClick) => {
return (
<ExportCSVButton
btnText='Down CSV'
onClick={ () => this.handleExportCSVButtonClick(onClick) }/>
);
}
//...
const options = {
exportCSVBtn: this.createCustomExportCSVButton
};
//...
<BootstrapTable data={rows} options={options} exportCSV>
ExportCSVButton
is not satisfied to your requirement, you can custom a new one as following
createCustomExportCSVButton = (onClick) => {
return (
<button style={ { color: 'red' } } onClick={ onClick }>Delete rows</button>
);
}
//...
const options = {
deleteBtn: this.createCustomExportCSVButton
};
//...
<BootstrapTable data={rows} options={options} exportCSV>
showSelectedOnlyBtn
in options
props,
showSelectedOnlyBtn
only accept a function and a JSX returned value is necessary. This function will take two argument: onClick
and showSelected
.
Following, we have two way to customize the select only toggle button:
ShowSelectedOnlyButton
by defaultShowSelectedOnlyButton
is a exported React component by
react-bootstrap-table
, and it have following props you can configure:
import { BootstrapTable, TableHeaderColumn, ShowSelectedOnlyButton } from 'react-bootstrap-table';
// ...
handleShowSelectButtonClick = (onClick) => {
// Custom your onClick event here,
// it's not necessary to implement this function if you have no any process before onClick
console.log('This is my custom function for ShowSelectedOnlyButton click event');
onClick();
}
createCustomShowSelectButton = (onClick, showSelected) => {
return (
<ExportCSVButton
className='my-custom-class'
onClick={ () => this.handleShowSelectButtonClick(onClick) }/>
);
}
//...
const selectRow = {
mode: 'radio',
showOnlySelected: true
};
const options = {
showSelectedOnlyBtn: this.createCustomShowSelectButton
};
//...
<BootstrapTable data={rows} options={options} selectRow={selectRow} exportCSV>
ExportCSVButton
is not satisfied to your requirement, you can custom a new one as following
createCustomExportCSVButton = (onClick) => {
return (
<button style={ { color: 'red' } } onClick={ onClick }>Delete rows</button>
);
}
//...
const options = {
deleteBtn: this.createCustomExportCSVButton
};
//...
<BootstrapTable data={rows} options={options} exportCSV>
searchPanel
in options
props.
searchPanel
only accept a function and a JSX returned value is necessary. This function will take one argument: props
.
and it have following properties you can use:
renderCustomSearchPanel = props => {
/**
* This function only pass one argument, is props object has following properties
* {
* searchField, // the search input field JSX
* clearBtn, // clear search button JSX
* defaultValue, // the default value for searching
* placeholder, // placeholder for search input field
* clearBtnClick, // the callback for triggering clear button click event
* search // the callback function for triggering search event, call it with a string text for searching
* }
***/
return (
...
);
}
// ...
const options = {
searchPanel: this.renderCustomSearchPanel
};
// ...
<BootstrapTable data={rows} options={options} search>
searchField
in options
props.
searchField
only accept a function and a JSX returned value is necessary. Following, we have two way to customize the search field:
SearchField
by defaultSearchField
is a exported React component by
react-bootstrap-table
, and it have following props you can configure:
import { BootstrapTable, TableHeaderColumn, SearchField } from 'react-bootstrap-table';
// ...
createCustomSearchField = (props) => {
return (
<SearchField
className='my-custom-class'
defaultValue='2000'
placeholder='Input a number'/>
);
}
//...
const options = {
searchField: this.createCustomSearchField
};
//...
<BootstrapTable data={rows} options={options} search>
SearchField
is not satisfied to your requirement, you can custom a new one as following
class MySearchField extends React.Component {
// It's necessary to implement getValue
getValue() {
return ReactDOM.findDOMNode(this).value;
}
// It's necessary to implement setValue
setValue(value) {
ReactDOM.findDOMNode(this).value = value;
}
render() {
return (
<input
className={ `form-control` }
type='text'
defaultValue={ this.props.defaultValue }
placeholder={ this.props.placeholder }
onKeyUp={ this.props.search }/>
);
}
}
//...
const options = {
searchField: (props) => (<MySearchField { ...props }/>)
};
//...
<BootstrapTable data={rows} options={options} search>
clearSearchBtn
in options
props.
clearSearchBtn
only accept a function and a JSX returned value is necessary.
Following, we have two way to customize the clear search button:
ClearSearchButton
by defaultClearSearchButton
is a exported React component by
react-bootstrap-table
, and it have following props you can configure:
import { BootstrapTable, TableHeaderColumn, ClearSearchButton } from 'react-bootstrap-table';
// ...
handleClearButtonClick = (onClick) => {
// Custom your onClick event here,
// it's not necessary to implement this function if you have no any process before onClick
console.log('This is my custom function for ClearSearchButton click event');
onClick();
}
createCustomClearButton = (onClick) => {
return (
<ClearSearchButton
btnText='MyClear'
btnContextual='btn-warning'
className='my-custom-class'
onClick={ e => this.handleClearButtonClick(onClick) }/>
);
}
//...
const options = {
clearSearch: true,
clearSearchBtn: this.createCustomClearButton
};
//...
<BootstrapTable data={rows} options={options} search>
ClearSearchButton
is not satisfied to your requirement, you can custom a new one as following
createCustomClearButton = (onClick) => {
return (
<button className='btn btn-warning' onClick={ onClick }>Clean</button>
);
}
//...
const options = {
clearSearch: true,
clearSearchBtn: this.createCustomClearButton
};
//...
<BootstrapTable data={rows} options={options} search>
react-bootstrap-table
all support it.
options.insertModal
and
we give you the event callback, props and some informations:
onModalClose
, onSave
, columns
, validateState
, ignoreEditable
You can follow this example
to learn how to custom the insert modal.
options.insertModalBody
and
we give you following arguments:
columns
, onSave
, validateState
, ignoreEditable
You can follow this example
to learn how to custom the body of insert modal.
Note: You are supposed to be wrapper your custom DOM/JSX as a React Component, for customizing body, we don't have the exposed React Component.
Note: You are supposed to be implemented the getFieldValue
method in your custom React Component and return the new row for insert row
customInsertEditor
on <TableHeaderColumn>
and give an object which have a getElement
property:
customNameField = (column, attr, editorClass, ignoreEditable) => {
return (
<select className={ `${editorClass}` } { ...attr }>
{
fruits.map(name => (<option key={ name } value={ name }>{ name }</option>))
}
</select>
);
}
// ...
<TableHeaderColumn dataField='name' customInsertEditor={ { getElement: this.customNameField } }>Product Name</TableHeaderColumn>
attr
props have ref
attribute and you are supposed to be add them on your input field(input, textarea, select etc.)
Because react-bootstrap-table
use the ref
to get the input value. However, if your custom element is not a standard field for HTML form-control
, you can still custom it like following:
class SalesRadioField extends React.Component {
getFieldValue = () => {
return this.refs.yes.checked ? 'Yes' : 'No';
}
render() {
return (
<div>
<label className='radio-inline'>
<input ref='yes' type='radio' name='optradio' value='Yes'/>Yes
</label>
<label className='radio-inline'>
<input ref='no' type='radio' name='optradio' value='No'/>No
</label>
</div>
);
}
}
customSaleField = (column, attr, editorClass, ignoreEditable) => {
/*
In this case, you are suppose to be prodived a specific method name for
react-bootstrap-table to get the value for this field.
Notes:
1. You are suppose to be implement getFieldValue function and return the value that user input
*/
return (
<SalesRadioField ref={ attr.ref } editorClass={ editorClass } ignoreEditable={ ignoreEditable }/>
);
}
// ...
<TableHeaderColumn dataField='sales' customInsertEditor={ { getElement: this.customSaleField } }>On Sales?</TableHeaderColumn>
options.insertModalHeader
, it only accept a function and a JSX returned value is necessary.
This function will take two argument: closeModal
and save
. This both are function, call the first one will trigger closing and the other will save your new data.
Following, we have two way to customize the header of insert modal:
InsertModalHeader
by defaultInsertModalHeader
component:
beforeClose(e) {
alert(`[Custom Event]: Before modal close event triggered!`);
}
handleModalClose(closeModal) {
// Custom your onCloseModal event here,
// it's not necessary to implement this function if you have no any process before modal close
console.log('This is my custom function for modal close event');
closeModal();
}
createCustomModalHeader = (closeModal, save) => {
return (
<InsertModalHeader
className='my-custom-class'
title='This is my custom title'
beforeClose={ this.beforeClose }
onModalClose={ () => this.handleModalClose(closeModal) }/>
// hideClose={ true } to hide the close button
);
// If you want have more power to custom the child of InsertModalHeader,
// you can do it like following
// return (
// <InsertModalHeader
// beforeClose={ this.beforeClose }
// onModalClose={ () => this.handleModalClose(closeModal) }>
// { ... }
// </InsertModalHeader>
// );
}
//...
const options = {
insertModalHeader: this.createCustomModalHeader
};
<BootstrapTable data={rows} options={options} insertRow>
InsertModalHeader
:
createCustomModalHeader(onClose, onSave) {
const headerStyle = {
fontWeight: 'bold',
fontSize: 'large',
textAlign: 'center',
backgroundColor: '#eeeeee'
};
return (
<div className='modal-header' style={ headerStyle }>
<h3>That is my custom header</h3>
<button className='btn btn-info' onClick={ onClose }>Close it!</button>
</div>
);
}
//...
const options = {
insertModalHeader: this.createCustomModalHeader
};
<BootstrapTable data={rows} options={options} insertRow>
options.insertModalFooter
, it only accept a function and a JSX returned value is necessary.
This function will take two argument: closeModal
and save
. This both are function, call the first one will trigger closing and the other will save your new data.
Following, we have two way to customize the footer of insert modal:
InsertModalFooter
by defaultInsertModalFooter
component:
beforeClose(e) {
alert(`[Custom Event]: Modal close event triggered!`);
}
beforeSave(e) {
alert(`[Custom Event]: Modal save event triggered!`);
}
handleModalClose(closeModal) {
// Custom your onCloseModal event here,
// it's not necessary to implement this function if you have no any process before modal close
console.log('This is my custom function for modal close event');
closeModal();
}
handleSave(save) {
// Custom your onSave event here,
// it's not necessary to implement this function if you have no any process before save
console.log('This is my custom function for save event');
save();
}
createCustomModalFooter = (closeModal, save) => {
return (
<InsertModalFooter
className='my-custom-class'
saveBtnText='CustomSaveText'
closeBtnText='CustomCloseText'
closeBtnContextual='btn-warning'
saveBtnContextual='btn-success'
closeBtnClass='my-close-btn-class'
saveBtnClass='my-save-btn-class'
beforeClose={ this.beforeClose }
beforeSave={ this.beforeSave }
onModalClose={ () => this.handleModalClose(closeModal) }
onSave={ () => this.handleSave(save) }/>
);
// If you want have more power to custom the child of InsertModalFooter,
// you can do it like following
// return (
// <InsertModalFooter
// onModalClose={ () => this.handleModalClose(closeModal) }
// onSave={ () => this.handleSave(save) }>
// { ... }
// </InsertModalFooter>
// );
}
//...
const options = {
insertModalFooter: this.createCustomModalFooter
};
<BootstrapTable data={rows} options={options} insertRow>
InsertModalFooter
:
createCustomModalFooter = (onClose, onSave) => {
const style = {
backgroundColor: '#ffffff'
};
return (
<div className='modal-footer' style={ style }>
<h3>Its a Custom footer</h3>
<button className='btn btn-xs btn-info' onClick={ onClose }>Leave</button>
<button className='btn btn-xs btn-danger' onClick={ onSave }>Confirm</button>
</div>
);
}
//...
const options = {
insertModalFooter: this.createCustomModalFooter
};
<BootstrapTable data={rows} options={options} insertRow>
options.paginationPanel
and
we give a props
as argument and this argument have following properties:
{
currPage,
sizePerPage,
sizePerPageList,
pageStartIndex,
changePage, // call it when page change and pass the new value of page
toggleDropDown, // call it for toggle sizePerPage dropdown
changeSizePerPage, // call it when sizePerPage change and pass the new value of size per page
components: { // Default pagination components, you can still use them
totalText,
sizePerPageDropdown,
pageList,
}
}
Following is a good example to getting started:
renderPaginationPanel = (props) => {
return (
<div>
<div>{ props.components.pageList }</div>
<div>
<span>Change size per page: </span>
{ props.components.sizePerPageDropdown }
</div>
<div>
<button onClick={ () => props.changeSizePerPage(25) } className='btn btn-default'>Click to force size per page as 25</button>
<button onClick={ () => props.toggleDropDown() } className='btn btn-default'>Click to force toggle dropdown</button>
<button onClick={ () => props.changePage(3) } className='btn btn-default'>Jump to page 3</button>
</div>
</div>
);
}
//...
const options = {
paginationPanel: this.renderPaginationPanel
};
//...
<BootstrapTable data={rows} options={options} pagination>
options.sizePerPageDropdown
props.
options.sizePerPageDropdown
only accept a function and a JSX returned value is necessary. Following, we have two way to customize the sizePerPage dropdown:
SizePerPageDropDown
by defaultSizePerPageDropDown
is a exported React component by
react-bootstrap-table
, and it have following props you can configure:
import { BootstrapTable, TableHeaderColumn, SizePerPageDropDown } from 'react-bootstrap-table';
// ...
onToggleDropDown = (toggleDropDown) => {
// do your stuff here
console.log('toggle dropdown');
toggleDropDown();
}
renderSizePerPageDropDown = (props) => {
return (
<SizePerPageDropDown
className='my-size-per-page'
btnContextual='btn-warning'
variation='dropup'
onClick={ () => this.onToggleDropDown(props.toggleDropDown) }/>
);
}
render() {
const options = {
sizePerPageDropDown: this.renderSizePerPageDropDown
};
//...
<BootstrapTable data={rows} options={options} pagination>
SizePerPageDropDown
is not satisfied to your requirement, you can custom a new one as following
renderSizePerPageDropDown = props => {
return (
<div className='btn-group'>
{
[ 10, 25, 30 ].map((n, idx) => {
const isActive = (n === props.currSizePerPage) ? 'active' : null;
return (
<button key={ idx } type='button' className={ `btn btn-info ${isActive}` } onClick={ () => props.changeSizePerPage(n) }>{ n }</button>
);
})
}
</div>
);
}
//...
const options = {
sizePerPageDropDown: this.renderSizePerPageDropDown
};
//...
<BootstrapTable data={rows} options={options} pagination>
type
: Give 'CustomFilter'
to specify this filter are customization filtergetElement
: Give a function and a JSX returned value is necessarycustomFilterParameters(optional)
: give any custom parameter if necessarycellEdit
prop on BootstrapTable
, the default editor is basic input field. react-bootstrap-table support some default form input,
like: textarea, checkbox, select and checkbox. You can confgiure editable
on TableHeaderColumn
to specify what kind of editor you want:
const jobTypes = [ 'A', 'B', 'C', 'D' ];
render() {
return (
<BootstrapTable data={ jobs } cellEdit={ cellEditProp }>
<TableHeaderColumn dataField='id' isKey={ true }}>Job ID</TableHeaderColumn}>
<TableHeaderColumn dataField='name' editable={ { type: 'textarea' } }}>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}>
<TableHeaderColumn dataField='datetime' editable={ { type: 'datetime' } }}>Date Time</TableHeaderColumn}>
</BootstrapTable>
);
}
customEditor
on TableHeaderColumn
.
There are two availabe properties can be configured on customEditor
:
getElement
: Give a function and a JSX returned value is necessarycustomEditorParameters(optional)
: give any custom parameter if necessaryupdateData()
on your customization component and return the cell data. This function will be called automatically before saving cell
selectRow
on BootstrapTable
, default will display a selection column on the first column. We only support className
and bgColor
for adding custom class name or background color on selection row.
render() {
const selectRow = {
mode: 'checkbox',
bgColor: 'pink',
className: 'my-selection-custom'
};
return (
<BootstrapTable data={ jobs } selectRow={ selectRow }>
<TableHeaderColumn dataField='id' isKey={ true }}>Job ID</TableHeaderColumn}>
<TableHeaderColumn dataField='name'>Job Name</TableHeaderColumn}>
<TableHeaderColumn dataField='type'>Job Type</TableHeaderColumn}>
</BootstrapTable>
);
}
selectRow.customComponent
. You can
check this example to learn how to use it.