mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-28 13:10:03 +00:00
add example for rich cell editor
This commit is contained in:
64
packages/react-bootstrap-table2-example/examples/cell-edit/checkbox-editor-table.js
vendored
Normal file
64
packages/react-bootstrap-table2-example/examples/cell-edit/checkbox-editor-table.js
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
/* eslint react/prefer-stateless-function: 0 */
|
||||
import React from 'react';
|
||||
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
|
||||
import Code from 'components/common/code-block';
|
||||
import { todosGenerator } from 'utils/common';
|
||||
|
||||
const todos = todosGenerator();
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Todo ID'
|
||||
}, {
|
||||
dataField: 'todo',
|
||||
text: 'Todo Name'
|
||||
}, {
|
||||
dataField: 'done',
|
||||
text: 'Done',
|
||||
editor: {
|
||||
type: Type.CHECKBOX,
|
||||
value: 'Y:N'
|
||||
}
|
||||
}];
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Todo ID'
|
||||
}, {
|
||||
dataField: 'todo',
|
||||
text: 'Todo Name'
|
||||
}, {
|
||||
dataField: 'done',
|
||||
text: 'Done',
|
||||
editor: {
|
||||
type: Type.CHECKBOX,
|
||||
value: 'Y:N'
|
||||
}
|
||||
}];
|
||||
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ todos }
|
||||
columns={ columns }
|
||||
cellEdit={ cellEditFactory({ mode: 'click', blurToSave: true }) }
|
||||
/>
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<h3>Dropdown Editor</h3>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ todos }
|
||||
columns={ columns }
|
||||
cellEdit={ cellEditFactory({ mode: 'click', blurToSave: true }) }
|
||||
/>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
130
packages/react-bootstrap-table2-example/examples/cell-edit/custom-editor-table.js
vendored
Normal file
130
packages/react-bootstrap-table2-example/examples/cell-edit/custom-editor-table.js
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
/* eslint react/prefer-stateless-function: 0 */
|
||||
/* eslint no-return-assign: 0 */
|
||||
/* eslint no-unused-vars: 0 */
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import cellEditFactory from 'react-bootstrap-table2-editor';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsQualityGenerator } from 'utils/common';
|
||||
|
||||
const products = productsQualityGenerator();
|
||||
|
||||
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: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'quality',
|
||||
text: 'Product Quality',
|
||||
editorRenderer: (editorProps, value, row, column, rowIndex, columnIndex) => (
|
||||
<QualityRanger { ...editorProps } value={ value } />
|
||||
)
|
||||
}];
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import cellEditFactory from 'react-bootstrap-table2-editor';
|
||||
|
||||
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: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'quality',
|
||||
text: 'Product Quality',
|
||||
editorRenderer: (editorProps, value, row, rowIndex, columnIndex) => (
|
||||
<QualityRanger { ...editorProps } value={ value } />
|
||||
)
|
||||
}];
|
||||
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
cellEdit={ cellEditFactory({ mode: 'click', blurToSave: true }) }
|
||||
/>
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<h3>Dropdown Editor</h3>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
cellEdit={ cellEditFactory({ mode: 'click', blurToSave: true }) }
|
||||
/>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
77
packages/react-bootstrap-table2-example/examples/cell-edit/date-editor-table.js
vendored
Normal file
77
packages/react-bootstrap-table2-example/examples/cell-edit/date-editor-table.js
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
/* eslint prefer-template: 0 */
|
||||
/* eslint react/prefer-stateless-function: 0 */
|
||||
import React from 'react';
|
||||
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
|
||||
import Code from 'components/common/code-block';
|
||||
import { stockGenerator } from 'utils/common';
|
||||
|
||||
const stocks = stockGenerator();
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Name'
|
||||
}, {
|
||||
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
|
||||
}
|
||||
}];
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Name'
|
||||
}, {
|
||||
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
|
||||
}
|
||||
}];
|
||||
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ stocks }
|
||||
columns={ columns }
|
||||
cellEdit={ cellEditFactory({ mode: 'click', blurToSave: true }) }
|
||||
/>
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<h3>Dropdown Editor</h3>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ stocks }
|
||||
columns={ columns }
|
||||
cellEdit={ cellEditFactory({ mode: 'click', blurToSave: true }) }
|
||||
/>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
100
packages/react-bootstrap-table2-example/examples/cell-edit/dropdown-editor-table.js
vendored
Normal file
100
packages/react-bootstrap-table2-example/examples/cell-edit/dropdown-editor-table.js
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
/* eslint react/prefer-stateless-function: 0 */
|
||||
import React from 'react';
|
||||
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
|
||||
import Code from 'components/common/code-block';
|
||||
import { jobsGenerator } from 'utils/common';
|
||||
|
||||
const jobs = jobsGenerator();
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Job ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Job Name'
|
||||
}, {
|
||||
dataField: 'owner',
|
||||
text: 'Job Owner'
|
||||
}, {
|
||||
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'
|
||||
}]
|
||||
}
|
||||
}];
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Job ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Job Name'
|
||||
}, {
|
||||
dataField: 'owner',
|
||||
text: 'Job Owner'
|
||||
}, {
|
||||
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'
|
||||
}]
|
||||
}
|
||||
}];
|
||||
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ jobs }
|
||||
columns={ columns }
|
||||
cellEdit={ cellEditFactory({ mode: 'click', blurToSave: true }) }
|
||||
/>
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<h3>Dropdown Editor</h3>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ jobs }
|
||||
columns={ columns }
|
||||
cellEdit={ cellEditFactory({ mode: 'click', blurToSave: true }) }
|
||||
/>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
68
packages/react-bootstrap-table2-example/examples/cell-edit/textarea-editor-table.js
vendored
Normal file
68
packages/react-bootstrap-table2-example/examples/cell-edit/textarea-editor-table.js
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
/* eslint react/prefer-stateless-function: 0 */
|
||||
import React from 'react';
|
||||
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
|
||||
import Code from 'components/common/code-block';
|
||||
import { jobsGenerator } from 'utils/common';
|
||||
|
||||
const jobs = jobsGenerator();
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Job ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Job Name'
|
||||
}, {
|
||||
dataField: 'owner',
|
||||
text: 'Job Owner'
|
||||
}, {
|
||||
dataField: 'type',
|
||||
text: 'Job Type',
|
||||
editor: {
|
||||
type: Type.TEXTAREA
|
||||
}
|
||||
}];
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Job ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Job Name'
|
||||
}, {
|
||||
dataField: 'owner',
|
||||
text: 'Job Owner'
|
||||
}, {
|
||||
dataField: 'type',
|
||||
text: 'Job Type',
|
||||
editor: {
|
||||
type: Type.TEXTAREA
|
||||
}
|
||||
}];
|
||||
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ jobs }
|
||||
columns={ columns }
|
||||
cellEdit={ cellEditFactory({ mode: 'click', blurToSave: true }) }
|
||||
/>
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<h3>Dropdown Editor</h3>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ jobs }
|
||||
columns={ columns }
|
||||
cellEdit={ cellEditFactory({ mode: 'click', blurToSave: true }) }
|
||||
/>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint no-mixed-operators: 0 */
|
||||
|
||||
/**
|
||||
* products generator for stories
|
||||
*
|
||||
@@ -27,12 +29,34 @@ export const productsQualityGenerator = (quantity = 5) =>
|
||||
quality: index % 3
|
||||
}));
|
||||
|
||||
const jobType = ['A', 'B', 'C', 'D', 'E'];
|
||||
|
||||
const jobOwner = ['Allen', 'Bob', 'Cindy'];
|
||||
|
||||
export const jobsGenerator = (quantity = 5) =>
|
||||
Array.from({ length: quantity }, (value, index) => ({
|
||||
id: index,
|
||||
name: `Job name ${index}`,
|
||||
owner: Math.floor(Math.random() * 3),
|
||||
type: Math.floor(Math.random() * 5)
|
||||
owner: jobOwner[Math.floor((Math.random() * 2) + 1)],
|
||||
type: jobType[Math.floor((Math.random() * 4) + 1)]
|
||||
}));
|
||||
|
||||
export const todosGenerator = (quantity = 5) =>
|
||||
Array.from({ length: quantity }, (value, index) => ({
|
||||
id: index,
|
||||
todo: `Todo item ${index}`,
|
||||
done: Math.random() > 0.4 ? 'Y' : 'N'
|
||||
}));
|
||||
|
||||
const startDate = new Date(2017, 0, 1);
|
||||
const endDate = new Date();
|
||||
|
||||
export const stockGenerator = (quantity = 5) =>
|
||||
Array.from({ length: quantity }, (value, index) => ({
|
||||
id: index,
|
||||
name: `Todo item ${index}`,
|
||||
inStockDate:
|
||||
new Date(startDate.getTime() + Math.random() * (endDate.getTime() - startDate.getTime()))
|
||||
}));
|
||||
|
||||
export const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
@@ -79,6 +79,11 @@ import CellEditStyleTable from 'examples/cell-edit/cell-edit-style-table';
|
||||
import CellEditClassTable from 'examples/cell-edit/cell-edit-class-table';
|
||||
import EditorStyleTable from 'examples/cell-edit/editor-style-table';
|
||||
import EditorClassTable from 'examples/cell-edit/editor-class-table';
|
||||
import DropdownEditorTable from 'examples/cell-edit/dropdown-editor-table';
|
||||
import TextareaEditorTable from 'examples/cell-edit/textarea-editor-table';
|
||||
import CheckboxEditorTable from 'examples/cell-edit/checkbox-editor-table';
|
||||
import DateEditorTable from 'examples/cell-edit/date-editor-table';
|
||||
import CustomEditorTable from 'examples/cell-edit/custom-editor-table';
|
||||
|
||||
// work on row selection
|
||||
import SingleSelectionTable from 'examples/row-selection/single-selection';
|
||||
@@ -200,7 +205,12 @@ storiesOf('Cell Editing', module)
|
||||
.add('Custom Cell Style', () => <CellEditStyleTable />)
|
||||
.add('Custom Cell Classes', () => <CellEditClassTable />)
|
||||
.add('Custom Editor Classes', () => <EditorClassTable />)
|
||||
.add('Custom Editor Style', () => <EditorStyleTable />);
|
||||
.add('Custom Editor Style', () => <EditorStyleTable />)
|
||||
.add('Dropdown Editor', () => <DropdownEditorTable />)
|
||||
.add('Textarea Editor', () => <TextareaEditorTable />)
|
||||
.add('Checkbox Editor', () => <CheckboxEditorTable />)
|
||||
.add('Date Editor', () => <DateEditorTable />)
|
||||
.add('Custom Editor', () => <CustomEditorTable />);
|
||||
|
||||
storiesOf('Row Selection', module)
|
||||
.add('Single Selection', () => <SingleSelectionTable />)
|
||||
|
||||
Reference in New Issue
Block a user