feat(动态控制过滤列,并提供回调函数):

This commit is contained in:
wanghaoo 2018-09-04 10:16:53 +08:00
parent 3a2d0328e4
commit ba0dab7110
4 changed files with 113 additions and 100 deletions

View File

@ -220,7 +220,7 @@
overflow-x: scroll;
padding-bottom: 20px;
margin-bottom: -20px;
overflow-y: auto;
overflow-y: scroll;
box-sizing: border-box; }
.u-table-title {
padding: 12px 8px;

View File

@ -32,6 +32,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
function noop() {}
/**
* 参数: 过滤表头
* @param {*} Table
@ -65,11 +66,11 @@ function filterColumn(Table, Popover) {
FilterColumn.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
if (nextProps.columns != this.props.columns) {
this.setState({
columns: (0, _utils.ObjectAssign)(nextProps.columns)
columns: this.setColumOrderByIndex((0, _utils.ObjectAssign)(nextProps.columns))
});
}
this.setState({
showModal: false
showModal: nextProps.showFilterPopover ? true : false
});
};
@ -87,7 +88,7 @@ function filterColumn(Table, Popover) {
widthState = 0,
scroll = scrollPro;
columns.forEach(function (da) {
if (da.disable) {
if (da.ifshow) {
_columns.push(da);
if (da.width) {
widthState++;
@ -142,20 +143,30 @@ function filterColumn(Table, Popover) {
return FilterColumn;
}(_react.Component), _class.defaultProps = {
prefixCls: "u-table-filter-column"
prefixCls: "u-table-filter-column",
afterFilter: noop,
scroll: {}
}, _initialiseProps = function _initialiseProps() {
var _this2 = this;
this.setColumOrderByIndex = function (_column) {
_column.forEach(function (da) {
//默认所有的列都显示如果传递ifshow属性根据ifshow属性值来判断是否显示某列
if (da.hasOwnProperty('ifshow')) {
da.checked = da.ifshow ? true : false;
da.ifshow = da.checked;
} else {
da.checked = true;
da.disable = true;
da.ifshow = true;
}
});
return _column;
};
this.checkedColumItemClick = function (da) {
var checkMinSize = _this2.props.checkMinSize;
var _props2 = _this2.props,
checkMinSize = _props2.checkMinSize,
afterFilter = _props2.afterFilter;
// if(checkMinSize)
var sum = 0,
@ -170,8 +181,10 @@ function filterColumn(Table, Popover) {
if (sum <= 1 && da.checked) return;
}
da.checked = da.checked ? false : true;
da.disable = da.checked ? true : false;
da.ifshow = da.checked ? true : false;
_this2.setState(_extends({}, _this2.state));
afterFilter(da, _this2.state.columns);
};
this.openCloumList = function () {
@ -207,7 +220,7 @@ function filterColumn(Table, Popover) {
columns.forEach(function (da) {
da.checked = true;
da.disable = true;
da.ifshow = true;
});
_this2.setState(_extends({}, _this2.state));
};
@ -219,7 +232,7 @@ function filterColumn(Table, Popover) {
sum += da.width;
}
});
console.log("sum", sum);
// console.log("sum",sum);
return sum;
};
}, _temp;

View File

@ -82,7 +82,7 @@ function sort(Table, Icon) {
};
_this.renderColumnsDropdown = function (columns) {
var prefixCls = _this.props.prefixCls || "bee-table";
var prefixCls = "bee-table";
return columns.map(function (originColumn) {
var column = _extends({}, originColumn);
var sortButton = void 0;

View File

@ -1,6 +1,6 @@
{
"name": "bee-table",
"version": "1.3.6",
"version": "1.3.7",
"description": "Table ui component for react",
"keywords": [
"react",