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

增强DsTable服务端筛选的功能

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