angular2-grid icon indicating copy to clipboard operation
angular2-grid copied to clipboard

Cancel a drop (decide when to cancel)

Open tudorgergely opened this issue 9 years ago • 3 comments

After releasing a drag, how can you determine if the position for release if valid or not?

If this is not currently possible, do you think this is something that would fit into this library? I would like to do a pull request when I am done.

I think we could use some function which will return true/false if the position is valid and act accordingly.

If you have a better idea please tell me.

Have a nice day!

tudorgergely avatar May 16 '16 11:05 tudorgergely

At the moment there is no invalid position for release. At the moment the grid allows for any drop location within the grid, and if it's outside the grid, it'll be the nearest location.

What would be your criteria for an invalid position? Also, what would be a use case for this function?

BTMorton avatar May 21 '16 12:05 BTMorton

This would be useful if you want in your application to prevent certain positions from being dropped on.

Let's say you want to only allow placing items in even columns. This is not possible currently. We can go even further and say you want 3x3 items to only be allowed on row 3 (and so on, I guess you see my point).

What I did in my fork of you project is that I created a service which is the injected both in the app and in NgGridItem directive. In the app I can add a new validator function and in NgGridItem i can check the position in setGridPosition to see if it valid.

This, unfortunately, breaks some functionality (which relies on the fact that an item can always be moved everywhere). But I am confident that we can actually make this work (and honestly would be very useful).

Here is the service I was telling you about: https://github.com/Catalysts/angular2-grid/blob/demo-eocs/src/service/GridPositionService.ts . The implementation is pretty basic but I guess it is all we need for now.

What needs to be rethought is the way we find valid positions and what happens if we cannot find one (because that would be possible now).

I am sure you have more ideas, what do you think?

tudorgergely avatar May 22 '16 11:05 tudorgergely

Actually, in the fixed items branch, there is a catch for fixed items that prevents moving certain items out of the way. A simple implementation of this could be to add a canDrop function binding which takes in a function similar to the one from your service. Should be do-able (y)

BTMorton avatar May 29 '16 20:05 BTMorton