mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
patch docs and story for #583
This commit is contained in:
parent
858ad9543b
commit
f7a06401ae
@ -62,6 +62,24 @@ const cellEdit = {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you want to perform a async `beforeSaveCell`, you can do it like that:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const cellEdit: {
|
||||||
|
// omit...
|
||||||
|
beforeSaveCell(oldValue, newValue, row, column, done) {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (confirm('Do you want to accep this change?')) {
|
||||||
|
done(); // contine to save the changes
|
||||||
|
} else {
|
||||||
|
done(false); // reject the changes
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
return { async: true };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
### <a name='afterSaveCell'>cellEdit.afterSaveCell - [Function]</a>
|
### <a name='afterSaveCell'>cellEdit.afterSaveCell - [Function]</a>
|
||||||
This callback function will be called after updating cell.
|
This callback function will be called after updating cell.
|
||||||
|
|
||||||
|
|||||||
86
packages/react-bootstrap-table2-example/examples/cell-edit/cell-edit-async-hooks-table.js
vendored
Normal file
86
packages/react-bootstrap-table2-example/examples/cell-edit/cell-edit-async-hooks-table.js
vendored
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
/* eslint no-unused-vars: 0 */
|
||||||
|
/* eslint no-console: 0 */
|
||||||
|
/* eslint no-alert: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import cellEditFactory from 'react-bootstrap-table2-editor';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } 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 = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import cellEditFactory from 'react-bootstrap-table2-editor';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
function beforeSaveCell(oldValue, newValue, row, column, done) {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (confirm('Do you want to accep this change?')) {
|
||||||
|
done(true);
|
||||||
|
} else {
|
||||||
|
done(false);
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
return { async: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
cellEdit={ cellEditFactory({
|
||||||
|
mode: 'click',
|
||||||
|
beforeSaveCell
|
||||||
|
}) }
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
function beforeSaveCell(oldValue, newValue, row, column, done) {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (confirm('Do you want to accep this change?')) {
|
||||||
|
done(true);
|
||||||
|
} else {
|
||||||
|
done(false);
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
return { async: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<h2>You will get a confirm prompt when you try to save a cell</h2>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
cellEdit={ cellEditFactory({
|
||||||
|
mode: 'click',
|
||||||
|
beforeSaveCell
|
||||||
|
}) }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
@ -97,6 +97,7 @@ import RowLevelEditableTable from 'examples/cell-edit/row-level-editable-table';
|
|||||||
import ColumnLevelEditableTable from 'examples/cell-edit/column-level-editable-table';
|
import ColumnLevelEditableTable from 'examples/cell-edit/column-level-editable-table';
|
||||||
import CellLevelEditable from 'examples/cell-edit/cell-level-editable-table';
|
import CellLevelEditable from 'examples/cell-edit/cell-level-editable-table';
|
||||||
import CellEditHooks from 'examples/cell-edit/cell-edit-hooks-table';
|
import CellEditHooks from 'examples/cell-edit/cell-edit-hooks-table';
|
||||||
|
import AsyncCellEditHooks from 'examples/cell-edit/cell-edit-async-hooks-table';
|
||||||
import CellEditValidator from 'examples/cell-edit/cell-edit-validator-table';
|
import CellEditValidator from 'examples/cell-edit/cell-edit-validator-table';
|
||||||
import AsyncCellEditValidator from 'examples/cell-edit/cell-edit-async-validator-table';
|
import AsyncCellEditValidator from 'examples/cell-edit/cell-edit-async-validator-table';
|
||||||
import CellEditStyleTable from 'examples/cell-edit/cell-edit-style-table';
|
import CellEditStyleTable from 'examples/cell-edit/cell-edit-style-table';
|
||||||
@ -289,6 +290,7 @@ storiesOf('Cell Editing', module)
|
|||||||
.add('Column Level Editable', () => <ColumnLevelEditableTable />)
|
.add('Column Level Editable', () => <ColumnLevelEditableTable />)
|
||||||
.add('Cell Level Editable', () => <CellLevelEditable />)
|
.add('Cell Level Editable', () => <CellLevelEditable />)
|
||||||
.add('Rich Hook Functions', () => <CellEditHooks />)
|
.add('Rich Hook Functions', () => <CellEditHooks />)
|
||||||
|
.add('Async Hook Functions', () => <AsyncCellEditHooks />)
|
||||||
.add('Validation', () => <CellEditValidator />)
|
.add('Validation', () => <CellEditValidator />)
|
||||||
.add('Async Validation', () => <AsyncCellEditValidator />)
|
.add('Async Validation', () => <AsyncCellEditValidator />)
|
||||||
.add('Auto Select Text Input', () => <AutoSelectTextInput />)
|
.add('Auto Select Text Input', () => <AutoSelectTextInput />)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user