【发布时间】:2019-07-09 16:36:11
【问题描述】:
是否可以设置您在所附屏幕截图中看到的分组行的样式?我想做的是提供一个 React 组件来代替它。
Here 是所附屏幕截图的代码框。
屏幕截图显示,代表该分组行的div 的类是react-grid-row-group,而它出现在React-Data-Grid 代码库中的唯一位置是RowGroup.tsx。
const RowGroup = forwardRef<HTMLDivElement, Props>(function RowGroup(props, ref) {
function onRowExpandToggle(expand?: boolean) {
const { onRowExpandToggle } = props.cellMetaData;
if (onRowExpandToggle) {
const shouldExpand = expand == null ? !props.isExpanded : expand;
onRowExpandToggle({ rowIdx: props.idx, shouldExpand, columnGroupName: props.columnGroupName, name: props.name });
}
}
function onRowExpandClick() {
onRowExpandToggle(!props.isExpanded);
}
function onClick() {
props.eventBus.dispatch(EventTypes.SELECT_CELL, { rowIdx: props.idx, idx: 0 });
}
const lastColumn = props.columns[props.columns.length - 1];
const style = { width: lastColumn!.left + lastColumn!.width };
const Renderer = props.renderer || DefaultBase;
return (
<div className="react-grid-row-group" style={style} onClick={onClick}>
<Renderer {...props} ref={ref} onRowExpandClick={onRowExpandClick} onRowExpandToggle={onRowExpandToggle} />
</div>
);
});
export default RowGroup;
因此,如果该组件接收到 renderer 属性,它将使用它来呈现具有上述类名的 div 下的组行。
RowGroup.tsx 的用法基本上在Canvas.tsx 中,Canvas 实例化RowGroup,renderer 属性为this.props.rowGroupRenderer。画布在Viewport.tsx 中呈现。 Viewport 在Grid.tsx 中渲染,Grid 在ReactDataGrid 中渲染。
【问题讨论】: