
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
react-bootstrap-table2-editor
Advanced tools
react-bootstrap-table2
separate the cell edit code base to react-bootstrap-table2-editor
, so there's a little bit different when you use cell edit than react-bootstrap-table
. In the following, we are going to show you how to enable the cell edit
$ npm install react-bootstrap-table2-editor --save
We have two ways to trigger a editable cell as editing cell:
That's look into how we enable the cell edit on tabe:
import cellEditFactory from 'react-bootstrap-table2-editor';
// omit
<BootstrapTable
keyField="id"
data={ products }
columns={ columns }
cellEdit={ cellEditFactory({ mode: 'click' }) }
/>
How user save their new editings? We offer two ways:
react-bootstrap-table2
support you to configure the cell editable on three level:
column.validator will help you to work on it!
react-bootstrap-table2
have following predefined editor:
In a nutshell, you just only give a column.editor and define the type
:
import { Type } from 'react-bootstrap-table2-editor';
const columns = [
..., {
dataField: 'done',
text: 'Done',
editor: {
type: Type.SELECT | Type.TEXTAREA | Type.CHECKBOX | Type.DATE,
... // The rest properties will be rendered into the editor's DOM element
}
}
]
In the following, we go though all the predefined editors:
Dropdown editor give a select menu to choose a data from a list, the editor.options
is required property for dropdown editor.
import { Type } from 'react-bootstrap-table2-editor';
const columns = [
..., {
dataField: 'type',
text: 'Job Type',
editor: {
type: Type.SELECT,
options: [{
value: 'A',
label: 'A'
}, {
value: 'B',
label: 'B'
}, {
value: 'C',
label: 'C'
}, {
value: 'D',
label: 'D'
}, {
value: 'E',
label: 'E'
}]
}
}];
Date editor is use <input type="date">
, the configuration is very simple:
const columns = [
..., {
dataField: 'inStockDate',
text: 'Stock Date',
formatter: (cell) => {
let dateObj = cell;
if (typeof cell !== 'object') {
dateObj = new Date(cell);
}
return `${('0' + dateObj.getDate()).slice(-2)}/${('0' + (dateObj.getMonth() + 1)).slice(-2)}/${dateObj.getFullYear()}`;
},
editor: {
type: Type.DATE
}
}];
Textarea editor is use <input type="textarea">
, user can press ENTER
to change line and in the react-bootstrap-table2
, user allow to save result via press SHIFT
+ ENTER
.
const columns = [
..., {
dataField: 'comment',
text: 'Product Comments',
editor: {
type: Type.TEXTAREA
}
}];
Checkbox editor allow you to have a pair value choice, the editor.value
is required value to represent the actual value for check and uncheck.
const columns = [
..., {
dataField: 'comment',
text: 'Product Comments',
editor: {
type: Type.CHECKBOX,
value: 'Y:N'
}
}];
If you feel above predefined editors are not satisfied to your requirement, you can certainly custom the editor via column.editorRenderer. It accept a function and pass following arguments when function called:
editorProps
: Some useful attributes you can use on DOM editor, like class, style etc.value
: Current cell valuerow
: Current row datacolumn
: Current column definitionrowIndex
: Current row indexcolumnIndex
: Current column indexNote when implement a custom React editor component, this component should have a getValue function which return current value on editor
Note when you want to save value, you can call editorProps.onUpdate function
Following is a short example:
class QualityRanger extends React.Component {
static propTypes = {
value: PropTypes.number,
onUpdate: PropTypes.func.isRequired
}
static defaultProps = {
value: 0
}
getValue() {
return parseInt(this.range.value, 10);
}
render() {
const { value, onUpdate, ...rest } = this.props;
return [
<input
{ ...rest }
key="range"
ref={ node => this.range = node }
type="range"
min="0"
max="100"
/>,
<button
key="submit"
className="btn btn-default"
onClick={ () => onUpdate(this.getValue()) }
>
done
</button>
];
}
}
const columns = [
..., {
dataField: 'quality',
text: 'Product Quality',
editorRenderer: (editorProps, value, row, column, rowIndex, columnIndex) => (
<QualityRanger { ...editorProps } value={ value } />
)
}];
FAQs
it's the editor addon for react-bootstrap-table2
The npm package react-bootstrap-table2-editor receives a total of 7,750 weekly downloads. As such, react-bootstrap-table2-editor popularity was classified as popular.
We found that react-bootstrap-table2-editor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.