Table editor
React Bootstrap 5 Table editor plugin
Table Editor is a useful tool for displaying and managing data. The component works similarly to the React Datatable (docs) with an additional column for action buttons.
Responsive interactive built with the latest Bootstrap 5. Creates editable tables. Delete or edit rows directly or via modal editor.Note: Read the API tab to find all available options and advanced customization
Basic example
You can initialize the component with MDBTableEditor
.
Company | Address | Employees |
---|---|---|
Smith & Johnson | Park Lane 2, London | 30 |
P.J. Company | Oak Street 7, Aberdeen | 80 |
Food & Wine | Netherhall Gardens 3, Hampstead | 12 |
IT Service | Warwick Road 14, London | 17 |
A. Jonson Gallery | Oaklands Avenue 2, London | 4 |
F.A. Architects | Frognal Way 7, Hampstead | 4 |
Modal
To change the default editing mode (inline) to the modal version, set property
modal
to true
.
Inputs example
Table Editor supports several input types - for example, if you wish to force a user to enter
only Boolean values in one column, you can set its
inputType
to a checkbox.
Supported input types:
- Text (default)
- Number
- Checkbox - displays a checkbox in edit mode and true/false value otherwise
- Select - additionally requires an array of options
Disable edit
You can disable editing for a table by setting its editable
property to
false
. A user won't be able to change its value in the edit mode.
Confirm delete
If you want to prevent data from being accidentally removed, you can set a
confirm
option to true
. In this case, Table Editor will show a
Popconfirm element before removing an entry.
Advanced Search
You can create more advanced searching functionality and allow a user to specify in which column to search for a given phrase.
Search fields need to be disabled manually in the edit mode.
Async data
While awaiting data from API, you can prevent a user from interacting with Table Editor by
managing loading
property.
Custom rows
The add()
method takes an optional argument - a row which values will be
preloaded into a new entry.
Note: for this particular use, a row has to be an object.
Note: as adding buttons are initialized manually, they won't be automatically disabled in the edit mode.
M.B.
(5 Avenue 26, New York)
Berkley & Clark
(43th Street 12, New York)
D&D Inc.
(14 Street 67, New York)
Thomas & Co.
(2 Avenue 54, New York)
Notifications
In this example, handlers for custom events trigger notifications after adding/deleting/updating an entry.
Dark
Dark mode can be applied to both modal and inline versions - firstly, add a CSS class which
changes the background color to your page. Secondly, pass the same class name to the
color
option of your Table Editor (f.e. 'bg-dark'). Now change the font to light
by setting dark
attribute to true
.
Company | Address | Employees |
---|---|---|
Smith & Johnson | Park Lane 2, London | 30 |
P.J. Company | Oak Street 7, Aberdeen | 80 |
Food & Wine | Netherhall Gardens 3, Hampstead | 12 |
IT Service | Warwick Road 14, London | 17 |
A. Jonson Gallery | Oaklands Avenue 2, London | 4 |
F.A. Architects | Frognal Way 7, Hampstead | 4 |
Table editor - API
Import
Properties
MDBTableEditor
Name | Type | Default | Description | Example |
---|---|---|---|---|
actionHeader
|
ReactNode | 'Actions' |
Header for action buttons |
<MDBTableEditor actionHeader='custom header' />
|
actionPosition
|
String | 'start' | 'end' |
Decides where to render an action column (start/end) |
<MDBTableEditor actionPosition='end' />
|
advancedSearch
|
SelectData[] | - |
Allows searching only for values in specific column |
<MDBTableEditor advancedSearch={[
{ text: 'All columns', value: '' },
{ text: 'Company', value: 'company' },
{ text: 'Office', value: 'office' },
]} />
|
allText
|
string | 'All' |
Changes text for All in the pagination select. |
<MDBTableEditor allText='test' />
|
bordered
|
boolean | false |
Adds borders to a TableEditor. |
<MDBTableEditor bordered />
|
borderless
|
boolean | false |
Removes all borders from a TableEditor. |
<MDBTableEditor borderless />
|
borderColor
|
string | - |
Changes a border color to one of main colors. |
<MDBTableEditor borderColor='red' />
|
cancelText
|
ReactNode | 'Cancel' |
Text displayed in cancel buttons |
<MDBTableEditor cancelText='Cancel' />
|
confirmText
|
ReactNode | 'Delete' |
Text displayed in confirm buttons (Popconfirm) |
<MDBTableEditor confirmText='custom confirm text' />
|
confirmMessage
|
ReactNode | 'Are you sure you want to delete this entry?' |
Text displayed in a Popconfirm element |
<MDBTableEditor confirmMessage='custom confirm message' />
|
color |
string | - |
Adds a color class to a TableEditor (f.e 'bg-dark') |
<MDBTableEditor color='primary' />
|
data |
DataType | - |
Data passed to the TableEditor. |
<MDBTableEditor data={data} />
|
dark |
boolean | false |
Changes a font color to white. |
<MDBTableEditor dark />
|
editable
|
boolean | true |
Enable the edit mode. |
<MDBTableEditor editable />
|
editItemHeader
|
ReactNode | 'Edit item' |
A header of modal |
<MDBTableEditor editItemHeader='Adding item' />
|
entries
|
number | 10 |
Number of visible entries (pagination). |
<MDBTableEditor entries={25} />
|
entriesOptions
|
number[] | [10, 25, 50, 200] |
Options available to choose from in a pagination select (rows per page). |
<MDBTableEditor entriesOptions=[10, 20, 60] />
|
fixedHeader
|
boolean | false |
When it's set to true, the table's header will remain visible while scrolling. |
<MDBTableEditor fixedHeader />
|
format
|
(field: string | number | symbol, value: number) => CSSProperties | undefined; | - |
Allows formatting cells |
<MDBTableEditor format={(field, value) => {
if (field === 'age' && value > 60) {
return { backgroundColor: '#999' };
}
}} />
|
fullPagination
|
boolean | false |
Displays additional buttons for the first and last pages. |
<MDBTableEditor fullPagination />
|
hover |
boolean | false |
Changes the background color of a hovered row. |
<MDBTableEditor hover />
|
isLoading
|
boolean | false |
Set the loading mode. |
<MDBTableEditor isLoading />
|
loaderClass
|
string | 'bg-primary' |
The class name for a loader (loading mode). |
<MDBTableEditor loaderClass='bg-warning' />
|
loadingMessage
|
ReactNode | 'Loading results...' |
A message displayed while loading data. |
<MDBTableEditor loadingMessage='Loading...' />
|
maxWidth
|
string | - |
Sets a maximum width of a TableEditor - can be either a string ('10%') or a number of pixels. |
<MDBTableEditor maxWidth='560px' />
|
maxHeight
|
string | - |
Sets a maximum height of a TableEditor - can be either a string ('10%') or a number of pixels. |
<MDBTableEditor maxHeight='560px' />
|
mode |
'table' | 'modal' | 'table' |
Set table editor mode. |
<MDBTableEditor mode='modal' />
|
newItemHeader
|
ReactNode | 'New item' |
A header of modal |
<MDBTableEditor newItemHeader='Adding item' />
|
noFoundMessage
|
ReactNode | 'No matching results found' |
A message displayed when a table is empty. |
<MDBTableEditor noFoundMessage='Not found...' />
|
ofText
|
ReactNode | 'of' |
'of' text in the pagination |
<MDBTableEditor ofText='z' />
|
pagination
|
boolean | true |
Shows/hides the pagination panel. |
<MDBTableEditor pagination={false} />
|
saveText
|
ReactNode | 'Save' |
Text displayed in the save button (modal) | |
rowsText
|
string | 'Rows per page': |
A text indicating a number of rows per page. |
<MDBTableEditor rowsText='Rows:' />
|
search
|
boolean | false |
Enable search in the table. |
<MDBTableEditor search />
|
sm |
boolean | false |
Decreases a row's paddings. |
<MDBTableEditor sm />
|
striped
|
boolean | false |
Slightly changes the background's color in every other row. |
<MDBTableEditor striped />
|
sortField
|
string | '' |
Allows default sorting of the table column |
<MDBTableEditor sortField='ColumnName' />
|
sortOrder
|
string | 'asc' |
Defines the default sorting direction |
<MDBTableEditor sortField='ColumnName' sortOrder='desc' />
|
searchInputProps
|
Record<string, unknown> | - |
Props for the search input |
<MDBTableEditor searchInputProps={{ className: 'test' }} />
|
Properties
DataType
ColumnsType
RowsType
Events
Name | Type | Description |
---|---|---|
onRowClick
|
(row: RecordsType) => void | Event emitted after clicking on a row. |
onAdd
|
(row: AdvancedRecord) => void | This event fires after adding a new row. |
onModify
|
(rows: RowsType, id: number) => void | This event fires when user modifies row. |
onDelete
|
(id: number) => void | This event fires after deleting a row. |