Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react-bootstrap-table2-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const columns = [
text: 'Job Type',
editor: {
type: Type.SELECT,
getOptions: () => [.....]
getOptions: (setOptions, { row, column }) => [.....]
}
}];

Expand All @@ -152,7 +152,7 @@ const columns = [
text: 'Job Type',
editor: {
type: Type.SELECT,
getOptions: (setOptions) => {
getOptions: (setOptions, { row, column }) => {
setTimeout(() => setOptions([...]), 1500);
}
}
Expand Down
10 changes: 9 additions & 1 deletion packages/react-bootstrap-table2-editor/src/dropdown-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ class DropDownEditor extends Component {
super(props);
let options = props.options;
if (props.getOptions) {
options = props.getOptions(this.setOptions.bind(this)) || [];
options = props.getOptions(
this.setOptions.bind(this),
{
row: props.row,
column: props.column
}
) || [];
}
this.state = { options };
}
Expand Down Expand Up @@ -54,6 +60,8 @@ class DropDownEditor extends Component {
}

DropDownEditor.propTypes = {
row: PropTypes.object.isRequired,
column: PropTypes.object.isRequired,
defaultValue: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
Expand Down
2 changes: 1 addition & 1 deletion packages/react-bootstrap-table2-editor/src/editing-cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export default (_, onStartEdit) =>
if (_.isFunction(column.editorRenderer)) {
editor = column.editorRenderer(editorProps, value, row, column, rowIndex, columnIndex);
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.SELECT) {
editor = <DropdownEditor { ...editorProps } />;
editor = <DropdownEditor { ...editorProps } row={ row } column={ column } />;
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.TEXTAREA) {
editor = <TextAreaEditor { ...editorProps } autoSelectText={ autoSelectText } />;
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.CHECKBOX) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint no-console: 0 */
/* eslint react/prefer-stateless-function: 0 */
import React from 'react';

Expand Down Expand Up @@ -25,22 +26,26 @@ const columns = [{
text: 'Job Type1',
editor: {
type: Type.SELECT,
getOptions: () => [{
value: 'A',
label: 'A'
}, {
value: 'B',
label: 'B'
}, {
value: 'C',
label: 'C'
}, {
value: 'D',
label: 'D'
}, {
value: 'E',
label: 'E'
}]
getOptions: (setOptions, { row, column }) => {
console.log(`current editing row id: ${row.id}`);
console.log(`current editing column: ${column.dataField}`);
return [{
value: 'A',
label: 'A'
}, {
value: 'B',
label: 'B'
}, {
value: 'C',
label: 'C'
}, {
value: 'D',
label: 'D'
}, {
value: 'E',
label: 'E'
}];
}
}
}, {
dataField: 'type2',
Expand Down Expand Up @@ -88,22 +93,26 @@ const columns = [{
text: 'Job Type1',
editor: {
type: Type.SELECT,
getOptions: () => [{
value: 'A',
label: 'A'
}, {
value: 'B',
label: 'B'
}, {
value: 'C',
label: 'C'
}, {
value: 'D',
label: 'D'
}, {
value: 'E',
label: 'E'
}]
getOptions: (setOptions, { row, column }) => {
console.log(\`current editing row id: $\{row.id}\`);
console.log(\`current editing column: $\{column.dataField}\`);
return [{
value: 'A',
label: 'A'
}, {
value: 'B',
label: 'B'
}, {
value: 'C',
label: 'C'
}, {
value: 'D',
label: 'D'
}, {
value: 'E',
label: 'E'
}];
}
}
}, {
dataField: 'type2',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import BootstrapTable from 'react-bootstrap-table-next';
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';

class Table extends React.Component {
filterByPrice = (filterVal) => {
filterByPrice = (filterVal, data) => {
if (filterVal) {
return products.filter(product => product.price == filterVal);
return data.filter(product => product.price == filterVal);
}
return products;
return data;
}

render() {
Expand Down Expand Up @@ -50,11 +50,11 @@ class Table extends React.Component {
`;

export default class Table extends React.Component {
filterByPrice = (filterVal) => {
filterByPrice = (filterVal, data) => {
if (filterVal) {
return products.filter(product => product.price == filterVal);
return data.filter(product => product.price == filterVal);
}
return products;
return data;
}

render() {
Expand All @@ -75,7 +75,7 @@ export default class Table extends React.Component {

return (
<div>
<h2>Implement Custom Filter</h2>
<h2>Implement a eq price filter</h2>
<BootstrapTable
keyField="id"
data={ products }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/* eslint react/prop-types: 0 */
import React from 'react';

import BootstrapTable from 'react-bootstrap-table-next';
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
import ToolkitProvider, { ColumnToggle } from 'react-bootstrap-table2-toolkit';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';

const { ToggleList } = ColumnToggle;
const products = productsGenerator();

const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name',
sort: true,
filter: textFilter()
}, {
dataField: 'price',
text: 'Product Price',
sort: true,
filter: textFilter()
}];

const sourceCode = `\
import BootstrapTable from 'react-bootstrap-table-next';
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
import ToolkitProvider, { ColumnToggle } from 'react-bootstrap-table2-toolkit';

const { ToggleList } = ColumnToggle;
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name',
sort: true,
filter: textFilter()
}, {
dataField: 'price',
text: 'Product Price',
sort: true,
filter: textFilter()
}];

<ToolkitProvider
keyField="id"
data={ products }
columns={ columns }
columnToggle
>
{
props => (
<div>
<ToggleList { ...props.columnToggleProps } />
<hr />
<BootstrapTable
{ ...props.baseProps }
filter={ filterFactory() }
/>
</div>
)
}
</ToolkitProvider>
`;

export default () => (
<div>
<h3>Table will keep the filter/sort state when column toggle</h3>
<ToolkitProvider
keyField="id"
data={ products }
columns={ columns }
columnToggle
>
{
props => (
<div>
<ToggleList { ...props.columnToggleProps } />
<hr />
<BootstrapTable
{ ...props.baseProps }
filter={ filterFactory() }
/>
</div>
)
}
</ToolkitProvider>
<Code>{ sourceCode }</Code>
</div>
);
6 changes: 4 additions & 2 deletions packages/react-bootstrap-table2-example/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ import BasicColumnToggle from 'examples/column-toggle';
import DefaultVisibility from 'examples/column-toggle/default-visibility';
import StylingColumnToggle from 'examples/column-toggle/styling-toggle-list';
import CustomToggleList from 'examples/column-toggle/custom-toggle-list';
import ColumnToggleWithFilter from 'examples/column-toggle/column-toggle-with-filter';

// loading overlay
import EmptyTableOverlay from 'examples/loading-overlay/empty-table-overlay';
Expand Down Expand Up @@ -443,15 +444,16 @@ storiesOf('Table Search', module)
.add('Default Search Table', () => <DefaultSearch />)
.add('Default Custom Search', () => <DefaultCustomSearch />)
.add('Fully Custom Search', () => <FullyCustomSearch />)
.add('Search Fromatted Value', () => <SearchFormattedData />)
.add('Search Formatted Value', () => <SearchFormattedData />)
.add('Custom Search Value', () => <CustomSearchValue />);

storiesOf('Column Toggle', module)
.addDecorator(bootstrapStyle())
.add('Basic Column Toggle', () => <BasicColumnToggle />)
.add('Default Visibility', () => <DefaultVisibility />)
.add('Styling Column Toggle', () => <StylingColumnToggle />)
.add('Custom Column Toggle', () => <CustomToggleList />);
.add('Custom Column Toggle', () => <CustomToggleList />)
.add('Column Toggle with Filter', () => <ColumnToggleWithFilter />);

storiesOf('Export CSV', module)
.addDecorator(bootstrapStyle())
Expand Down
30 changes: 22 additions & 8 deletions packages/react-bootstrap-table2-filter/src/components/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,27 @@ class DateFilter extends Component {
return optionTags;
}

getDefaultComparator() {
const { defaultValue, filterState } = this.props;
if (filterState && filterState.filterVal) {
return filterState.filterVal.comparator;
}
if (defaultValue && defaultValue.comparator) {
return defaultValue.comparator;
}
return '';
}

getDefaultDate() {
let defaultDate = '';
const { defaultValue } = this.props;
// Set the appropriate format for the input type=date, i.e. "YYYY-MM-DD"
const { defaultValue, filterState } = this.props;
if (filterState && filterState.filterVal && filterState.filterVal.date) {
return dateParser(filterState.filterVal.date);
}
if (defaultValue && defaultValue.date) {
// Set the appropriate format for the input type=date, i.e. "YYYY-MM-DD"
defaultDate = dateParser(new Date(defaultValue.date));
return dateParser(new Date(defaultValue.date));
}
return defaultDate;
return '';
}

applyFilter(value, comparator, isInitial) {
Expand Down Expand Up @@ -122,8 +135,7 @@ class DateFilter extends Component {
dateStyle,
className,
comparatorClassName,
dateClassName,
defaultValue
dateClassName
} = this.props;

return (
Expand All @@ -143,7 +155,7 @@ class DateFilter extends Component {
style={ comparatorStyle }
className={ `date-filter-comparator form-control ${comparatorClassName}` }
onChange={ this.onChangeComparator }
defaultValue={ defaultValue ? defaultValue.comparator : '' }
defaultValue={ this.getDefaultComparator() }
>
{ this.getComparatorOptions() }
</select>
Expand All @@ -169,6 +181,7 @@ class DateFilter extends Component {
DateFilter.propTypes = {
onFilter: PropTypes.func.isRequired,
column: PropTypes.object.isRequired,
filterState: PropTypes.object,
delay: PropTypes.number,
defaultValue: PropTypes.shape({
date: PropTypes.oneOfType([PropTypes.object]),
Expand Down Expand Up @@ -210,6 +223,7 @@ DateFilter.defaultProps = {
date: undefined,
comparator: ''
},
filterState: {},
withoutEmptyComparatorOption: false,
comparators: legalComparators,
placeholder: undefined,
Expand Down
Loading