Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detecting col-resize event #19

Open
yashshah12 opened this issue Jan 25, 2018 · 14 comments
Open

Detecting col-resize event #19

yashshah12 opened this issue Jan 25, 2018 · 14 comments

Comments

@yashshah12
Copy link

Is there a way to listen for a col-resize callback event and then the grid calls a callback with the column index, or something else.

Something like

<ReactGrid onColResize={this.handleResizeColumns} />

@alexkrolick
Copy link
Contributor

Dupe of #12?

@scamden
Copy link
Member

scamden commented Jan 26, 2018 via email

@yashshah12
Copy link
Author

Thanks man.

I figured out that we can do this to get the new width of the column we just resized:
this.grid.eventLoop.bind('grid-drag-end', (e) => { const col = e.col const newWidth = this.grid.view.col.get(col).width });

@scamden
Copy link
Member

scamden commented Jan 26, 2018 via email

@yashshah12
Copy link
Author

For sure, having the props will definitely be easier. But just until that is implemented, this will help us move along.

@yashshah12
Copy link
Author

yashshah12 commented Jan 26, 2018

I am noticing this weird behavior::

  • I expand the column, i see the initial width printed out
  • i detract the column and i see the expanded width printed out

Is it lagging or is it because my function runs and then your function runs which is where the width gets updated?

@yashshah12
Copy link
Author

Fixed the above issue by adding a delay

@scamden
Copy link
Member

scamden commented Jan 26, 2018 via email

@yashshah12
Copy link
Author

async updateColumnnWidth (col) {
	const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
	await delay(1000)

	if (col < 0 || !this.grid.view.col.get(col)) return
	const newWidth = this.grid.view.col.get(col).width

        ... code for updating data with the new width
}

setGrid = reactGrid => {
	if (!reactGrid) return
	this.grid = reactGrid.grid

	this.grid.eventLoop.bind('grid-drag-end', e => {
	  const col = e.col
	  this.updateColumnnWidth(col)

	  return true
	})
}

@alexkrolick
Copy link
Contributor

Yeah... let's not do that. This will cause all sorts of timing-related bugs.

@yashshah12
Copy link
Author

Yeah, we realized that, its a hacky solutions until we can pass grid event props

@scamden
Copy link
Member

scamden commented Jan 26, 2018

oh dude. instead of grid-drag-end use grid-col-change and then check e.action === 'size' the col (and row) changes can be fired with various actions like move, hide, add, remove so you can respond to any of these changes. the drag end event is really on any grid drag not just the resize. use the col change event and you shouldn't need the timeout.

and again i mentioned this on another issue but not sure if you caught it. you want to be using this.grid.data.col.get not this.grid.view.col.get (i realize the naming here is confusing but data and view are referring to a type of index "space" not whether it's in the data or the ui). if you didn't already read the docs on the grid repo i would def suggest it and ping me there with anything that needs clarifying :)

@scamden
Copy link
Member

scamden commented Jan 26, 2018

oh and better yet. you can get the column directly off the event like so e.descriptors[0].width. It maybe be preferable to do a forEach though because the grid can actually resize multiple columns at once. so e.descriptors.forEach(updateWidthForColumnObject), not sure what your update api looks like but i'm sure you could do this functionally by mapping over the descriptors and creating your update object instead if forEach makes you shudder.

@scamden
Copy link
Member

scamden commented Jan 26, 2018

also please make suggestions about naming and things you're finding confusing. i would love to improve the usability of the grid's apis and since v4 is in beta we have a good opportunity to rename or move things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants