当我们在React Data Grid中选择多个过滤器选项时,列标题会变得混乱。 有没有办法解决此问题,以便所选的筛选器选项显示在a中的一行上方 下拉列表而不是添加到列标题。随着新的过滤器键添加到列表中,列标题大小也在增长。
参考:https://github.com/adazzle/react-data-grid/issues/885
```
import React from 'react';
var ExecutionEnvironment = require('exenv');
if (ExecutionEnvironment.canUseDOM) {
var ReactDataGrid = require('react-data-grid');
var { Toolbar, Filters: { NumericFilter, AutoCompleteFilter, MultiSelectFilter, SingleSelectFilter }, Data: { Selectors } } = require('react-data-grid-addons');
}
export default class ReactGrid extends React.Component {
constructor(props, context) {
const { Toolbar, Filters: { NumericFilter, AutoCompleteFilter, MultiSelectFilter, SingleSelectFilter }, Data: { Selectors } } = require('react-data-grid-addons');
super(props, context);
this._columns = [
{
key: 'prd_family_name',
name: 'Product Family Name',
width: 190,
filterable: true,
filterRenderer: MultiSelectFilter,
sortable: true
},
{
key: 'prd_family_mkt',
name: 'Market',
width: 70,
filterable: true,
filterRenderer: AutoCompleteFilter,
sortable: true
}
];
console.log(`gridvalue${this.props.gridValues}`);
this.state = { filters: {} };
}
componentWillReceiveProps(nextProps) {
this.setState({ rows: nextProps.gridValues });
}
getRandomDate = (start, end) => new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime())).toLocaleDateString();
rowGetter = index => Selectors.getRows(this.state)[index];
rowsCount = () => Selectors.getRows(this.state).length;
handleFilterChange = (filter) => {
const newFilters = Object.assign({}, this.state.filters);
if (filter.filterTerm) {
newFilters[filter.column.key] = filter;
} else {
delete newFilters[filter.column.key];
}
this.setState({ filters: newFilters });
};
getValidFilterValues = (columnId) => {
const values = this.state.rows.map(r => r[columnId]);
return values.filter((item, i, a) => i === a.indexOf(item));
};
handleOnClearFilters = () => {
this.setState({ filters: {} });
};
handleGridSort = (sortColumn, sortDirection) => {
const comparer = (a, b) => {
if (sortDirection === 'ASC') {
return (a[sortColumn] > b[sortColumn]) ? 1 : -1;
} else if (sortDirection === 'DESC') {
return (a[sortColumn] < b[sortColumn]) ? 1 : -1;
}
};
const rows = sortDirection === 'NONE' ? this.state.originalRows.slice(0) : this.state.rows.sort(comparer);
this.setState({ rows });
};
render() {
return (
<ReactDataGrid
enableCellSelect
columns={this._columns}
rowGetter={this.rowGetter}
rowsCount={this.rowsCount()}
onGridSort={this.handleGridSort}
minHeight={450}
toolbar={<Toolbar enableFilter />}
onAddFilter={this.handleFilterChange}
getValidFilterValues={this.getValidFilterValues}
onClearFilters={this.handleOnClearFilters}
/>);
}
}
```
以上代码用于渲染数据网格。
答案 0 :(得分:1)
我看到了完全相同的问题。我已经对一堆CSS进行了排序,当你将鼠标移过时,它会破坏过滤器中的过滤器选择。
当鼠标移出时,它会回到水平布局并且溢出被剪裁。不是100%完美,但似乎对我来说做得很好。
您需要调整CSS中的一些值以使用您的字体/大小,但这应该是微不足道的。
.react-grid-Container
{
font-size : 10px;
font-family: Roboto Mono, sans-serif;
}
div.react-grid-HeaderCell .input-sm {
height: 30px;
padding: 5px 10px;
font-size: 12px;
line-height: 1.5;
border-radius: 3px;
max-width : 100%;
border : 1px solid #ddd;
}
div.react-grid-HeaderCell
{
font-family: Raleway, sans-serif;
font-weight: 700;
font-size: 11px;
}
div.react-grid-HeaderCell:hover
{
z-index:9999;
overflow:visible;
}
div.react-grid-HeaderCell:hover input:not(.Select-input)
{
max-width: 250px;
width: 250px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
div.react-grid-HeaderCell div.input-sm
{
display : none;
}
div.react-grid-HeaderCell:hover .Select div.Select-Value
{
clear:both;
}
div.react-grid-HeaderCell .Select-control
{
width: 100%;
}
div.react-grid-HeaderCell:hover .Select .Select-control,
div.react-grid-HeaderCell:hover .Select .Select-menu-outer
{
width: max-content;
min-width: 250px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
div.react-grid-HeaderCell:hover .Select .Select-control .Select-value
{
float: left;
clear: left;
margin-right : 20px;
}
div.react-grid-HeaderCell:hover .Select .Select-multi-value-wrapper
{
padding : 5px;
padding-top : 40px;
}
div.react-grid-HeaderCell:hover .Select div.Select-input
{
position : absolute;
left : 0;
width:max-content;
min-width : 220px;
margin-top : -35px;
margin-right : 20px;
border : 1px solid #ddd;
padding-right: 5px;
}
div.react-grid-HeaderCell:hover .Select--multi .Select-arrow-zone,
div.react-grid-HeaderCell:hover .Select--multi .Select-clear-zone
{
margin-left: 5px;
position : absolute;
}
div.react-grid-HeaderCell:hover .Select--multi .Select-arrow-zone
{
right : -3px;
top : 7px;
}
div.react-grid-HeaderCell:hover .Select--multi .Select-clear-zone
{
right : 3px;
bottom : 3px;
}
div.react-grid-HeaderCell:hover .Select--multi .Select-control .Select-value
{
max-height : 22px;
}
&#13;