mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
92 lines
1.8 KiB
JavaScript
92 lines
1.8 KiB
JavaScript
/* eslint no-unused-vars: 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',
|
|
validator: (newValue, row, column) => {
|
|
if (isNaN(newValue)) {
|
|
return {
|
|
valid: false,
|
|
message: 'Price should be numeric'
|
|
};
|
|
}
|
|
if (newValue < 2000) {
|
|
return {
|
|
valid: false,
|
|
message: 'Price should bigger than 2000'
|
|
};
|
|
}
|
|
return true;
|
|
}
|
|
}];
|
|
|
|
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',
|
|
validator: (newValue, row, column) => {
|
|
if (isNaN(newValue)) {
|
|
return {
|
|
valid: false,
|
|
message: 'Price should be numeric'
|
|
};
|
|
}
|
|
if (newValue < 2000) {
|
|
return {
|
|
valid: false,
|
|
message: 'Price should bigger than 2000'
|
|
};
|
|
}
|
|
return true;
|
|
}
|
|
}];
|
|
|
|
<BootstrapTable
|
|
keyField="id"
|
|
data={ products }
|
|
columns={ columns }
|
|
cellEdit={ cellEditFactory({
|
|
mode: 'click',
|
|
blurToSave: true
|
|
}) }
|
|
/>
|
|
`;
|
|
|
|
export default () => (
|
|
<div>
|
|
<h3>Product Price should bigger than $2000</h3>
|
|
<BootstrapTable
|
|
keyField="id"
|
|
data={ products }
|
|
columns={ columns }
|
|
cellEdit={ cellEditFactory({
|
|
mode: 'click',
|
|
blurToSave: true
|
|
}) }
|
|
/>
|
|
<Code>{ sourceCode }</Code>
|
|
</div>
|
|
);
|