mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
76 lines
1.7 KiB
JavaScript
76 lines
1.7 KiB
JavaScript
/* eslint no-unused-vars: 0 */
|
|
/* eslint arrow-body-style: 0 */
|
|
import React, { Component } from 'react';
|
|
|
|
import BootstrapTable from 'react-bootstrap-table2';
|
|
import Code from 'components/common/code-block';
|
|
import { productsGenerator, sleep } from 'utils/common';
|
|
|
|
const products = productsGenerator();
|
|
|
|
const columns = [{
|
|
dataField: 'id',
|
|
text: 'Product ID'
|
|
}, {
|
|
dataField: 'name',
|
|
text: 'Product Name'
|
|
}, {
|
|
dataField: 'price',
|
|
text: 'Product Price'
|
|
}];
|
|
|
|
const sourceCode = `\
|
|
class CellEditWithPromise extends Component {
|
|
handleCellEditing = (rowId, dataField, newValue) => {
|
|
return sleep(1000).then(() => {
|
|
if (dataField === 'price' && (newValue < 2000 || isNaN(newValue))) {
|
|
throw new Error('Product Price should bigger than $2000');
|
|
}
|
|
});
|
|
}
|
|
|
|
render() {
|
|
const cellEdit = {
|
|
mode: 'click',
|
|
blurToSave: true,
|
|
onUpdate: this.handleCellEditing
|
|
};
|
|
|
|
return (
|
|
<div>
|
|
<BootstrapTable keyField="id" data={ products } columns={ columns } cellEdit={ cellEdit } />
|
|
<Code>{ sourceCode }</Code>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
`;
|
|
|
|
class CellEditWithPromise extends Component {
|
|
handleCellEditing = (rowId, dataField, newValue) => {
|
|
return sleep(1000).then(() => {
|
|
if (dataField === 'price' && (newValue < 2000 || isNaN(newValue))) {
|
|
throw new Error('Product Price should bigger than $2000');
|
|
}
|
|
});
|
|
}
|
|
|
|
render() {
|
|
const cellEdit = {
|
|
mode: 'click',
|
|
blurToSave: true,
|
|
onUpdate: this.handleCellEditing
|
|
};
|
|
|
|
return (
|
|
<div>
|
|
<BootstrapTable keyField="id" data={ products } columns={ columns } cellEdit={ cellEdit } />
|
|
<Code>{ sourceCode }</Code>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default CellEditWithPromise;
|
|
|