增加是否可过滤API

This commit is contained in:
wanghaoo 2018-11-28 15:58:42 +08:00
parent 9ed6fd4cad
commit 3c91162336
1 changed files with 127 additions and 101 deletions

View File

@ -1,9 +1,9 @@
import React, { Component } from "react";
import Checkbox from 'bee-checkbox';
import Checkbox from "bee-checkbox";
import Icon from "bee-icon";
import {ObjectAssign} from './util';
import i18n from '../i18n'
import { getComponentLocale } from 'bee-locale/build/tool';
import { ObjectAssign } from "./util";
import i18n from "../i18n";
import { getComponentLocale } from "bee-locale/build/tool";
function noop() {}
/**
@ -14,13 +14,13 @@ function noop() {}
*/
export default function filterColumn(Table, Popover) {
return class FilterColumn extends Component {
static defaultProps = {
prefixCls: "u-table-filter-column",
afterFilter: noop,
columnFilterAble: true,
scroll: {}
}
};
constructor(props) {
super(props);
@ -32,10 +32,10 @@ export default function filterColumn(Table,Popover) {
};
}
setColumOrderByIndex = (_column)=>{
setColumOrderByIndex = _column => {
_column.forEach(da => {
//默认所有的列都显示如果传递ifshow属性根据ifshow属性值来判断是否显示某列
if(da.hasOwnProperty('ifshow')){
if (da.hasOwnProperty("ifshow")) {
da.checked = da.ifshow ? true : false;
da.ifshow = da.checked;
} else {
@ -44,22 +44,23 @@ export default function filterColumn(Table,Popover) {
}
});
return _column;
}
};
componentWillReceiveProps(nextProps) {
if (nextProps.columns != this.props.columns) {
this.setState({
columns: this.setColumOrderByIndex(ObjectAssign(nextProps.columns))
})
});
}
this.setState({
showModal: nextProps.showFilterPopover ? true : false
})
});
}
checkedColumItemClick = (da)=>{
checkedColumItemClick = da => {
let { checkMinSize, afterFilter } = this.props;
// if(checkMinSize)
let sum = 0,leng=0;
let sum = 0,
leng = 0;
this.state.columns.forEach(da => {
da.fixed ? "" : leng++;
!da.fixed && da.checked ? sum++ : "";
@ -74,29 +75,39 @@ export default function filterColumn(Table,Popover) {
this.setState({
...this.state
})
});
afterFilter(da, this.state.columns);
}
};
openCloumList = () => {
this.setState({
showModal: true
});
}
};
getCloumItem = () => {
const { prefixCls } = this.props;
const { columns } = this.state;
return columns.map((da,i)=>
{
return columns.map((da, i) => {
if (!da.fixed) {
return (<div key={da.key+"_"+i} className={`${prefixCls}-pop-cont-item`} >
<Checkbox id={da.key} checked={da.checked} onClick={()=>{this.checkedColumItemClick(da)}}/>
return (
<div
key={da.key + "_" + i}
className={`${prefixCls}-pop-cont-item`}
>
<Checkbox
id={da.key}
checked={da.checked}
onClick={() => {
this.checkedColumItemClick(da);
}}
/>
<span>{da.title}</span>
</div>)
}
})
</div>
);
}
});
};
clear = () => {
const { columns } = this.state;
@ -106,29 +117,36 @@ export default function filterColumn(Table,Popover) {
});
this.setState({
columns
})
});
this.props.afterFilter(this.state.columns, this.state.columns);
}
};
getCloumnsScroll=(columns)=>{
getCloumnsScroll = columns => {
let sum = 0;
columns.forEach((da)=>{
columns.forEach(da => {
if (da.checked) {
sum += da.width;
}
})
});
// console.log("sum",sum);
return (sum);
}
return sum;
};
render() {
const { data, prefixCls, scroll: scrollPro } = this.props;
const { columns, showModal } = this.state;
let locale = getComponentLocale(this.props, this.context, 'Table', () => i18n);
let locale = getComponentLocale(
this.props,
this.context,
"Table",
() => i18n
);
let _columns = [],widthState=0,scroll=scrollPro;
columns.forEach((da)=>{
let _columns = [],
widthState = 0,
scroll = scrollPro;
columns.forEach(da => {
if (da.ifshow) {
_columns.push(da);
if (da.width) {
@ -142,32 +160,40 @@ export default function filterColumn(Table,Popover) {
let content = (
<div className={`${prefixCls}-pop-cont`}>
<span className={`${prefixCls}-clear-setting`} onClick={this.clear}>{locale['resetSettings']}</span>
<div>
{
this.getCloumItem()
}
<span className={`${prefixCls}-clear-setting`} onClick={this.clear}>
{locale["resetSettings"]}
</span>
<div>{this.getCloumItem()}</div>
</div>
</div>);
);
return <div className={`${prefixCls}-cont`}>
<Table {...this.props} columns={_columns} data={data}
return (
<div className={`${prefixCls}-cont`}>
<Table
{...this.props}
columns={_columns}
data={data}
// scroll={scroll}
// scroll={{x:this.getCloumnsScroll(columns)}}
/>
{this.props.columnFilterAble == false ? (
""
) : (
<div className={`${prefixCls}-filter-icon`}>
<Popover
id="filter_column_popover"
placement="left"
content={content}
show={showModal} >
show={showModal}
>
<div className={`${prefixCls}-pop-column-filter-cont`}>
<Icon type="uf-grid" onClick={this.openCloumList} />
</div>
</Popover>
</div>
</div>;
)}
</div>
);
}
};
}