增加 autoCheckedByClickRows 参数,设置行点击是否自动勾选复选框
This commit is contained in:
parent
013eb36f0d
commit
b9b42ba052
|
@ -891,7 +891,7 @@ var Table = function (_Component) {
|
|||
|
||||
onHoverProps.onHover = this.handleRowHover;
|
||||
|
||||
if (props.height) {
|
||||
if (props.bodyDisplayInRow && props.height) {
|
||||
height = props.height;
|
||||
} else if (fixed || props.heightConsistent) {
|
||||
height = fixedColumnsBodyRowsHeight[fixedIndex];
|
||||
|
@ -1342,7 +1342,8 @@ var Table = function (_Component) {
|
|||
height = _props8.height,
|
||||
headerHeight = _props8.headerHeight,
|
||||
columns = _props8.columns,
|
||||
heightConsistent = _props8.heightConsistent;
|
||||
heightConsistent = _props8.heightConsistent,
|
||||
bodyDisplayInRow = _props8.bodyDisplayInRow;
|
||||
|
||||
var headRows = this.headTable ? this.headTable.querySelectorAll('thead') : this.bodyTable.querySelectorAll('thead');
|
||||
var bodyRows = this.bodyTable.querySelectorAll('.' + clsPrefix + '-row') || [];
|
||||
|
@ -1357,11 +1358,12 @@ var Table = function (_Component) {
|
|||
});
|
||||
var fixedColumnsBodyRowsHeight = [].map.call(bodyRows, function (row, index) {
|
||||
var rsHeight = height;
|
||||
if (rsHeight) {
|
||||
if (bodyDisplayInRow && rsHeight) {
|
||||
return rsHeight;
|
||||
} else {
|
||||
// 为了提高性能,默认获取主表的高度,但是有的场景中固定列的高度比主表的高度高,所以提供此属性,会统计所有列的高度取最大的,设置
|
||||
if (heightConsistent) {
|
||||
// 内容折行显示,并又设置了 height 的情况下,也要获取主表高度
|
||||
if (heightConsistent || !bodyDisplayInRow && rsHeight) {
|
||||
var leftHeight = void 0,
|
||||
rightHeight = void 0,
|
||||
currentHeight = void 0,
|
||||
|
@ -1544,7 +1546,8 @@ var Table = function (_Component) {
|
|||
}
|
||||
className += ' ' + clsPrefix + '-scroll-position-' + this.state.scrollPosition;
|
||||
//如果传入height说明是固定高度
|
||||
if (props.height) {
|
||||
//内容过多折行显示时,height 属性会失效,为了避免产生错行
|
||||
if (props.bodyDisplayInRow && props.height) {
|
||||
className += ' fixed-height';
|
||||
}
|
||||
if (props.bodyDisplayInRow) {
|
||||
|
|
|
@ -152,10 +152,13 @@ function multiSelect(Table, Checkbox) {
|
|||
};
|
||||
|
||||
return MultiSelect;
|
||||
}(_react.Component), _class.defaultProps = {
|
||||
}(_react.Component), _class.propTypes = {
|
||||
autoCheckedByClickRows: PropTypes.bool //行点击时,是否自动勾选复选框
|
||||
}, _class.defaultProps = {
|
||||
prefixCls: "u-table-mult-select",
|
||||
getSelectedDataFunc: function getSelectedDataFunc() {},
|
||||
autoSelect: false
|
||||
autoSelect: false,
|
||||
autoCheckedByClickRows: true
|
||||
}, _initialiseProps = function _initialiseProps() {
|
||||
var _this2 = this;
|
||||
|
||||
|
@ -340,10 +343,14 @@ function multiSelect(Table, Checkbox) {
|
|||
};
|
||||
|
||||
this.onRowClick = function (record, index, event) {
|
||||
_this2.onCheckboxChange('', record, index)();
|
||||
if (_this2.props.onRowClick) {
|
||||
_this2.props.onRowClick(record, index, event);
|
||||
var _props2 = _this2.props,
|
||||
autoCheckedByClickRows = _props2.autoCheckedByClickRows,
|
||||
onRowClick = _props2.onRowClick;
|
||||
|
||||
if (autoCheckedByClickRows) {
|
||||
_this2.onCheckboxChange('', record, index)();
|
||||
}
|
||||
onRowClick && onRowClick(record, index, event);
|
||||
};
|
||||
}, _temp;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* @title 基本表格
|
||||
* @parent 基础 Basic
|
||||
* @description 单元格数据过长时,可结合Tooltip组件使用。
|
||||
* @description 当单元格内容过多时,会自动显示省略号,鼠标hover有提示。showRowNum 设置是否显示序号列。
|
||||
* demo0101
|
||||
*/
|
||||
|
||||
|
|
|
@ -96,6 +96,7 @@ class Demo33 extends Component {
|
|||
data={data}
|
||||
multiSelect={{type: "checkbox"}}
|
||||
getSelectedDataFunc={this.getSelectedDataFunc}
|
||||
autoCheckedByClickRows={false} //行点击是否触发勾选动作
|
||||
/>
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -76,11 +76,12 @@ import 'bee-table/build/Table.css';
|
|||
| heightConsistent | 当固定列内容高度超出非固定列时,内容互错行,当此属性为true会将高度同步,当行过多时会有性能影响,所以建议非固定高度如果过高时,超出内容可以显示成省略号 | bool|false
|
||||
| height | 自定义表格行高 | number | - |
|
||||
| headerHeight | 自定义表头行高 | number | - |
|
||||
| headerDisplayInRow | 设置表头的内容显示一行,超出显示省略号 | bool |
|
||||
| bodyDisplayInRow | 设置表体的内容显示一行,超出显示省略号 | bool |
|
||||
| headerDisplayInRow | 设置表头的内容显示一行,超出显示省略号 | bool | true |
|
||||
| bodyDisplayInRow | 设置表体的内容显示一行,超出显示省略号,**注意:不要和 height 属性一起使用,该属性优先级高于 height** | bool | true |
|
||||
| size | 表格大小 | `sm / md / lg` | 'md' |
|
||||
| hideHeaderScroll | 表体无数据时,表头下是否显示滚动条,默认显示 | bool | false |
|
||||
| [v2.2.2新增]showRowNum | 展示序号功能,false时不展示,true时展示默认情况,可传入自定义配置信息 | bool / obj:{name: '序号', key: '_index', // 在数据中存储的key值width: 50,base: 0,// 排序的基准值,为数字或者字母type:'number', // 排序类型,默认为number类型,支持单字母排序(type='ascii')} | false |
|
||||
| autoCheckedByClickRows | 设置为 false 时,表格行点击事件,不会自动勾选复选框 | bool | true |
|
||||
|
||||
> 快捷键部分参考示例 (快捷键在table中的简单使用应用)
|
||||
|
||||
|
|
13
src/Table.js
13
src/Table.js
|
@ -736,8 +736,7 @@ class Table extends Component {
|
|||
onHoverProps.onHover = this.handleRowHover;
|
||||
|
||||
|
||||
|
||||
if (props.height) {
|
||||
if (props.bodyDisplayInRow && props.height) {
|
||||
height = props.height
|
||||
} else if(fixed || props.heightConsistent) {
|
||||
height = fixedColumnsBodyRowsHeight[fixedIndex];
|
||||
|
@ -1147,7 +1146,7 @@ class Table extends Component {
|
|||
|
||||
syncFixedTableRowHeight() {
|
||||
//this.props.height、headerHeight分别为用户传入的行高和表头高度,如果有值,所有行的高度都是固定的,主要为了避免在千行数据中有固定列时获取行高度有问题
|
||||
const { clsPrefix, height, headerHeight,columns,heightConsistent } = this.props;
|
||||
const { clsPrefix, height, headerHeight,columns,heightConsistent, bodyDisplayInRow } = this.props;
|
||||
const headRows = this.headTable ?
|
||||
this.headTable.querySelectorAll('thead') :
|
||||
this.bodyTable.querySelectorAll('thead');
|
||||
|
@ -1165,11 +1164,12 @@ class Table extends Component {
|
|||
const fixedColumnsBodyRowsHeight = [].map.call(
|
||||
bodyRows, (row,index) =>{
|
||||
let rsHeight = height;
|
||||
if(rsHeight){
|
||||
if(bodyDisplayInRow && rsHeight){
|
||||
return rsHeight;
|
||||
}else{
|
||||
// 为了提高性能,默认获取主表的高度,但是有的场景中固定列的高度比主表的高度高,所以提供此属性,会统计所有列的高度取最大的,设置
|
||||
if(heightConsistent){
|
||||
// 内容折行显示,并又设置了 height 的情况下,也要获取主表高度
|
||||
if(heightConsistent || (!bodyDisplayInRow && rsHeight)){
|
||||
let leftHeight,rightHeight,currentHeight,maxHeight;
|
||||
leftHeight = leftBodyRows[index]?leftBodyRows[index].getBoundingClientRect().height:0;
|
||||
rightHeight = rightBodyRows[index]?rightBodyRows[index].getBoundingClientRect().height:0;
|
||||
|
@ -1373,7 +1373,8 @@ class Table extends Component {
|
|||
}
|
||||
className += ` ${clsPrefix}-scroll-position-${this.state.scrollPosition}`;
|
||||
//如果传入height说明是固定高度
|
||||
if(props.height){
|
||||
//内容过多折行显示时,height 属性会失效,为了避免产生错行
|
||||
if(props.bodyDisplayInRow && props.height){
|
||||
className += ' fixed-height';
|
||||
}
|
||||
if(props.bodyDisplayInRow){
|
||||
|
|
|
@ -11,10 +11,14 @@ import {ObjectAssign} from './util';
|
|||
export default function multiSelect(Table, Checkbox) {
|
||||
|
||||
return class MultiSelect extends Component {
|
||||
static propTypes = {
|
||||
autoCheckedByClickRows: PropTypes.bool, //行点击时,是否自动勾选复选框
|
||||
};
|
||||
static defaultProps = {
|
||||
prefixCls: "u-table-mult-select",
|
||||
getSelectedDataFunc:()=>{},
|
||||
autoSelect: false
|
||||
autoSelect: false,
|
||||
autoCheckedByClickRows: true
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
|
@ -283,10 +287,11 @@ export default function multiSelect(Table, Checkbox) {
|
|||
|
||||
// 实现行点击时触发多选框勾选的需求
|
||||
onRowClick = (record,index,event) =>{
|
||||
this.onCheckboxChange('',record, index)();
|
||||
if( this.props.onRowClick ){
|
||||
this.props.onRowClick(record,index,event);
|
||||
let { autoCheckedByClickRows, onRowClick } = this.props;
|
||||
if(autoCheckedByClickRows) {
|
||||
this.onCheckboxChange('',record, index)();
|
||||
}
|
||||
onRowClick && onRowClick(record,index,event);
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
Loading…
Reference in New Issue