提交 486480ca authored 作者: vipcxj's avatar vipcxj

增强DsTable服务端筛选的功能

上级 8f5a5b32
...@@ -37,7 +37,7 @@ class DsTable extends React.Component { ...@@ -37,7 +37,7 @@ class DsTable extends React.Component {
total: num, total: num,
pageSize: this.state.pageSize, pageSize: this.state.pageSize,
}, },
onChange: (pagination) => { onChange: (pagination, filters, sorter) => {
this.setState({ this.setState({
current: pagination.current, current: pagination.current,
pageSize: pagination.pageSize, pageSize: pagination.pageSize,
......
...@@ -12,16 +12,16 @@ const getKeyName = (meta) => { ...@@ -12,16 +12,16 @@ const getKeyName = (meta) => {
}; };
const getSource = (property) => { const getSource = (property) => {
if (property.filter && property.filter.source) { if (property.source) {
let source = _.trim(property.filter.source); return (property.source.items || []).map((item) => {
if (source[0] !== '[') { try {
source = `[${source}]`; return JSON.parse(item);
} } catch (err) {
try { return item;
return JSON.parse(source); }
} catch (err) { });
return undefined; } else {
} return [];
} }
}; };
...@@ -64,12 +64,6 @@ const makeColumns = (meta) => { ...@@ -64,12 +64,6 @@ const makeColumns = (meta) => {
if (props.order === undefined) { if (props.order === undefined) {
props.order = 0; props.order = 0;
} }
if (props.visible === undefined) {
props.visible = true;
}
if (!props.visible) {
props.colSpan = 0;
}
if ((props.fixed === true || props.fixed === 'left' || props.fixed === 'right') && props.width === undefined) { if ((props.fixed === true || props.fixed === 'left' || props.fixed === 'right') && props.width === undefined) {
props.width = 150; props.width = 150;
} }
...@@ -77,10 +71,12 @@ const makeColumns = (meta) => { ...@@ -77,10 +71,12 @@ const makeColumns = (meta) => {
...props, ...props,
dataIndex: property.name, dataIndex: property.name,
key: property.name, key: property.name,
filterType: property.filter ? property.filter.type : undefined, sorter: property.sort,
filterType: property.filterType,
filterEnums: getSource(property), filterEnums: getSource(property),
}, _.negate(_.isUndefined)); }, _.negate(_.isUndefined));
}) })
.filter(c => c.visible !== false)
.sort((c1, c2) => { .sort((c1, c2) => {
const c1Left = c1.fixed === true || c1.fixed === 'left'; const c1Left = c1.fixed === true || c1.fixed === 'left';
const c1Right = c1.fixed === 'right'; const c1Right = c1.fixed === 'right';
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Checkbox, Button } from 'antd'; import { Checkbox, Button } from 'antd';
import { isString } from 'lodash';
import styles from './enum.less'; import styles from './enum.less';
class EnumSearch extends Component { class EnumSearch extends Component {
static getValue(filterEnum) {
if (isString(filterEnum)) {
return filterEnum;
} else {
return filterEnum ? filterEnum.value : null;
}
}
static getText(filterEnum) {
if (isString(filterEnum)) {
return filterEnum;
} else {
return filterEnum ? filterEnum.text : null;
}
}
constructor(props, context) { constructor(props, context) {
super(props, context); super(props, context);
...@@ -19,7 +34,7 @@ class EnumSearch extends Component { ...@@ -19,7 +34,7 @@ class EnumSearch extends Component {
const { onSearchSubmit } = this.props; const { onSearchSubmit } = this.props;
const values = this.props.filterEnums const values = this.props.filterEnums
.filter((filterEnum, index) => this.state.checked[index]) .filter((filterEnum, index) => this.state.checked[index])
.map(filterEnum => filterEnum.value); .map(filterEnum => EnumSearch.getValue(filterEnum));
if (values && values.length === 1) { if (values && values.length === 1) {
onSearchSubmit(`=${values[0]}`); onSearchSubmit(`=${values[0]}`);
} else if (values && values.length > 1) { } else if (values && values.length > 1) {
...@@ -48,7 +63,7 @@ class EnumSearch extends Component { ...@@ -48,7 +63,7 @@ class EnumSearch extends Component {
return ( return (
<span key={index}> <span key={index}>
<Checkbox checked={this.state.checked[index]} onChange={onChange}> <Checkbox checked={this.state.checked[index]} onChange={onChange}>
{ filterEnum.text } { EnumSearch.getText(filterEnum) }
</Checkbox> </Checkbox>
<br /> <br />
</span> </span>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论