react-data-grid icon indicating copy to clipboard operation
react-data-grid copied to clipboard

V7 column resize bugs

Open igoriok1994 opened this issue 5 years ago • 10 comments

Hi,

In V7 canary 16 now supported column width in percents. That's nice.

After some testing I found bug.

Steps:

  1. Dynamically set column width from props
<DataGrid
    columns={...}
>
  1. Do manual resize (adjust column width with mouse)
  2. Update grid columns prop (like in Step 1.). Now columns will not react on width property...

Here is the video report:

https://youtu.be/gGtp1-TsTx8

Here is the code:

require('!style!css!sass!./Temp_i_3.scss');

import React, { PureComponent } from 'react';
import _ from 'lodash';
import 'rdg.v7/dist/react-data-grid.css';
import DataGrid from 'rdg.v7';
import { AutoSizer } from 'react-virtualized';
import { Button } from '@c/button';

class Temp_i_3 extends PureComponent {
	constructor() {
		super();

		this.state = {
			cols: [
				{
					key: 'c1',
					name: 'c1',
					resizable: true,
					width: '15%'
				},
				{
					key: 'c2',
					name: 'c2',
					resizable: true
				},
				{
					key: 'c3',
					name: 'c3',
					resizable: true
				}
			]
		};
	}

	componentWillUnmount() {
		this._mounted = false;
	}

	componentDidMount() {
		this._mounted = true;
	}

	setRand1 = () => {
		let v = Math.floor(Math.random() * 400) + 50;

		let cols = _.cloneDeep(this.state.cols);
		cols[0].width = v;

		console.log("new width: ", v);

		this.setState({ cols });
	}

	setRand2 = () => {
		let v = Math.floor(Math.random() * 50) + 10;

		let cols = _.cloneDeep(this.state.cols);
		cols[0].width = `${v}%`;

		console.log("new width: ", `${v}%`);

		this.setState({ cols });
	}

	render() {
		return (
			<div className='ST_H100 ST_W100'>
				<AutoSizer>
					{({ height, width }) => (
						<React.Fragment>
							<DataGrid
								width={width}
								height={height - 35}
								columns={this.state.cols}
								rows={_.map(new Array(200), (v,i) => {
									return {
										c1: i,
										c2: i,
										c3: i
									};
								})}
							/>
							<div className='ST_ROW ST_MG-T' style={{width}}>
								<Button onClick={this.setRand1}>
									set random px width
								</Button>
								<Button onClick={this.setRand2}>
									set random % width
								</Button>
							</div>
						</React.Fragment>
					)}
				</AutoSizer>
			</div>
		);
	}
}

export default Temp_i_3;


igoriok1994 avatar May 22 '20 12:05 igoriok1994

Up

igoriok1994 avatar Jun 30 '20 08:06 igoriok1994

Any news? :)

@amanmahajan7

igoriok1994 avatar Aug 27 '20 14:08 igoriok1994

This needs further investigation for a possible solution.

amanmahajan7 avatar Sep 02 '20 12:09 amanmahajan7

Also, (V7 canary 16):

onColumnResize callback is called, when actual column size is lower than min column size

igoriok1994 avatar Sep 02 '20 13:09 igoriok1994

Any update on that PR?

djung31 avatar Mar 05 '21 17:03 djung31

I'm on version ^7.0.0-canary.41 and onColumnResize is called many times while changing the width rather than once when you let go of the mouse button. What I believe is the correct behavior is shown in this coder pad CoderPad (version 5)

chriswalz-bg avatar Apr 22 '21 19:04 chriswalz-bg

@amanmahajan7 Why did the PR end up being closed? Is there an alternative solution in the pipeline? Cheers

drunkenplatypus avatar Jun 21 '21 11:06 drunkenplatypus

any update on this issue, can we do something to help?

highwaycoder avatar Jun 30 '21 15:06 highwaycoder

any updates on this issue?

faithod avatar Jul 19 '22 17:07 faithod

We haven't found a good solution to this problem yet. We are open to suggestions. In the meantime you can add a key and reset the key when width is changed

amanmahajan7 avatar Aug 29 '22 17:08 amanmahajan7