This commit is contained in:
wanghaoo 2018-10-11 22:52:54 +08:00
commit 83fed7b012
6 changed files with 80 additions and 47 deletions

View File

@ -144,8 +144,21 @@ class Demo27 extends Component {
}
},
{ title: "姓名", width: 180, dataIndex: "name", key: "name", filterType: "text", filterDropdown: "show" },
{ title: "年龄", width: 150, sorter: (a, b) => a.age - b.age, dataIndex: "age", key: "age", filterType: "dropdown", filterDropdown: "show" },
{ title: "居住地址", width: 150, dataIndex: "address", key: "address", filterType: "dropdown", filterDropdown: "show" },
{
title: "年龄",
width: 150,
sorter: (a, b) => a.age - b.age,
dataIndex: "age",
key: "age",
filterType: "dropdown",
filterDropdown: "hide",
filterDropdownAuto: "manual",//切换手动传入模式
filterDropdownData: [{
key: '数据',
value: '数据'
}]
},
{ title: "居住地址", width: 150, dataIndex: "address", key: "address", filterType: "dropdown", filterDropdown: "hide" },
];
return <ComplexTable
onFilterRowsDropChange={this.handlerFilterRowsDropChange}//下拉条件的回调(key,val)=>()

File diff suppressed because one or more lines are too long

40
dist/demo.js vendored

File diff suppressed because one or more lines are too long

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -183,30 +183,30 @@ class Table extends Component {
}
}
computeTableWidth(){
//如果用户传了scroll.x按用户传的为主
let setWidthParam = this.props.scroll.x
if(typeof(setWidthParam) == 'number'){
let numSetWidthParam = parseInt(setWidthParam);
this.contentWidth = numSetWidthParam;
}else{
//计算总表格宽度、根据表格宽度和各列的宽度和比较,重置最后一列
this.contentDomWidth = this.contentTable.getBoundingClientRect().width//表格容器宽度
this.contentWidth = this.contentDomWidth;//默认与容器宽度一样
if(typeof(setWidthParam)=='string' && setWidthParam.indexOf('%')){
this.contentWidth = this.contentWidth * parseInt(setWidthParam) /100
}
}
const computeObj = this.columnManager.getColumnWidth(this.contentWidth);
let lastShowIndex = computeObj.lastShowIndex;
this.computeWidth = computeObj.computeWidth;
if(this.computeWidth < this.contentWidth){
let contentWidthDiff = this.contentWidth - this.computeWidth;
this.setState({contentWidthDiff,lastShowIndex});
}else{
this.contentWidth = this.computeWidth;
this.setState({contentWidthDiff:0,lastShowIndex});//重新渲染,为了显示滚动条
computeTableWidth() {
//如果用户传了scroll.x按用户传的为主
let setWidthParam = this.props.scroll.x
if (typeof (setWidthParam) == 'number') {
let numSetWidthParam = parseInt(setWidthParam);
this.contentWidth = numSetWidthParam;
} else {
//计算总表格宽度、根据表格宽度和各列的宽度和比较,重置最后一列
this.contentDomWidth = this.contentTable.getBoundingClientRect().width//表格容器宽度
this.contentWidth = this.contentDomWidth;//默认与容器宽度一样
if (typeof (setWidthParam) == 'string' && setWidthParam.indexOf('%')) {
this.contentWidth = this.contentWidth * parseInt(setWidthParam) / 100
}
}
const computeObj = this.columnManager.getColumnWidth(this.contentWidth);
let lastShowIndex = computeObj.lastShowIndex;
this.computeWidth = computeObj.computeWidth;
if (this.computeWidth < this.contentWidth) {
let contentWidthDiff = this.contentWidth - this.computeWidth;
this.setState({ contentWidthDiff, lastShowIndex });
} else {
this.contentWidth = this.computeWidth;
this.setState({ contentWidthDiff: 0, lastShowIndex });//重新渲染,为了显示滚动条
}
}
onExpandedRowsChange(expandedRowKeys) {
@ -349,7 +349,9 @@ class Table extends Component {
dataindex: column.dataIndex,
datasource: this.props.data,
format: column.format,
filterdropdown: column.filterDropdown
filterdropdown: column.filterDropdown,
filterdropdownauto: column.filterDropdownAuto,//是否自定义数据
filterdropdowndata: column.filterDropdownData//自定义数据格式
});
}
});
@ -529,7 +531,7 @@ class Table extends Component {
getColGroup(columns, fixed) {
let cols = [];
let self= this;
let self = this;
let { contentWidthDiff = 0, lastShowIndex = 0 } = this.state;
if (this.props.expandIconAsCell && fixed !== 'right') {
cols.push(
@ -551,9 +553,9 @@ class Table extends Component {
}
cols = cols.concat(leafColumns.map((c, i, arr) => {
let width = c.width;
if(typeof(width)=='string' && width.indexOf('%')>-1 && self.contentWidth){
width = parseInt(self.contentWidth * parseInt(width) /100);
}else if(width){
if (typeof (width) == 'string' && width.indexOf('%') > -1 && self.contentWidth) {
width = parseInt(self.contentWidth * parseInt(width) / 100);
} else if (width) {
width = parseInt(width);
}
if (lastShowIndex == i) {
@ -638,8 +640,8 @@ class Table extends Component {
tableStyle.width = this.contentWidth;
}
}
// 自动出现滚动条
if(this.contentDomWidth > this.contentWidth){
// 自动出现滚动条
if (this.contentDomWidth > this.contentWidth) {
tableStyle.width = this.contentDomWidth;
}
const tableBody = hasBody ? getBodyWrapper(

View File

@ -247,7 +247,7 @@ class TableHeader extends Component {
//下拉框选择
case 'dropdown':
let selectDataSource = [];
if (rows.length > 0) {
if (rows.length > 0 && (rows[1][index]['filterdropdownauto'] || 'auto') == 'auto') {
let hash = {};
//处理下拉重复对象组装dropdown
selectDataSource = Array.from(rows[1][0].datasource, x => ({ key: x[dataIndex], value: x[dataIndex] }));
@ -255,6 +255,8 @@ class TableHeader extends Component {
hash[next.key] ? '' : hash[next.key] = true && item.push(next);
return item
}, []);
} else {
selectDataSource = rows[1][index]['filterdropdowndata']
}
return <FilterType
rendertype={type}