Closed rufreakde closed 2 years ago
Ok I saw that when I do this the placeholder wont be resized and when I stop the values of the placeholder override the values of the item!
Also
maintain_ratio: true, does not work if you resize it just resizes the way you drag ( i tried it in your Demo and used your settings just changed to:
maintain_ratio: true,
And it does not maintain any ratio. Do I do something terribly wrong here?
OK, can you explain the behaviour that you're expecting here as I'm a little confused. Is it that when you move an item, it will be resized to fill the space in the row it's dragged into?
Some initial questions then: What have you bound the onItemDrag
method to? How is your config being generated - is it created on the fly or bound to a variable? Ideally, you should update the item config to change the sizex/sizey rather than calling the setSize
method, as that will cause issues internally.
maintain_ratio
is used with max_rows
, max_cols
, visible_rows
or visible_cols
in order to maintain the ratio of column width and row height. It will not fix the items to a set ratio of rows/cols if that's what you were expecting. If that is a feature you would like, please open a new issue to request it.
@BTMorton Yeah when I move an item from row 1 into row 2 it will be resized to fill the free row space of row 2. This is not a feature you have, I want to implement it. But my problem is that I cant resize the Item anyway. First I tried just to set sizex/sizey but this has no effect at all! Thats when I found the setter and thought that should be the right way doing it.
To the binding:
<div [ngGrid]="gridConfig" (window:pageshow)="onWindowResize($event)" (onDragStart)="onItemStartDrag($event)" (onDragStop)="onItemDragStop($event)"
(onItemChange)="onItemChange($event)" (onResize)="onItemResize($event)" (onDrag)="onItemDrag($event)">
My item config is per item on each element. And it is a variable i bind to it.
<div [ngGridItem]="gridItemConfig"...
Okay I misunderstood this I thought that if I set my sizex/sizey to 1/2 when i resize x=2 it would set y to 4. Sorry for that.
EDIT: event.sizex and event.sizey are readOnly with a getter? I cant set them i can only set the private _sizex/y but this is not intended right?
Modiffiing the config of the dragged item like this:
onItemStartDrag(event): void {
console.log(event._config);
event._config.sizex = 4;
event._config.sizey = 2;
}
Will result in an browser freeze. (newest version angular2 and chrome)
EDIT: it only freezes on the first one if I drag it somewhere without a layout interaction! I f I drag it beneath another item and they stay. There is no problem after that. Don't understand where the freeze comes from. There are no error massages. Can there be an infinite loop somewhere?
Okay here is a pretty dirty workaround:
In my GridComponent with your Grid Directive:
private tempItemSizeScale = {
x: 4,
y: 2
};
I had to use both methods to set the values! And in different event hooks!
onItemDrag(event): void {
event.setSize(this.tempItemSizeScale, true);
}
onItemDragStop(event) {
event._config.sizex = this.tempItemSizeScale.x;
event._config.sizey = this.tempItemSizeScale.y;
}
Now I can resize the Items without infinite loops. Is there a beautiful way to get the remaining "unused" cols of a row from the grid?
Cheers, rufreakde
Not in the grid. You'll have to use the items and the number of columns to calculate it yourself. Theoretically, you could use the item grid that is currently in place to get the free columns, but I'm going to be removing that soon as it's not the most efficient method of handling things, especially with large number of columns/rows
I try to resize my Item on drag, and fill the space of a row where a item is already in place. But the resize is always the sizex and sizey of the griditem!
Config:
On the grid I have an event and try to set the size:
Seems like this is applied to the temporary object and when I stop the drag the size is going back to the 3/3 of the griditem (min) ! Where can I hook to automatically resize when I drag beneath my other items to fill the empty space?