jaumard / ngx-dashboard

Dashboard library for angular 4 and more
https://jaumard.github.io/ngx-dashboard/demo/demoDist/index.html
MIT License
71 stars 31 forks source link

Render Widget size problem #20

Closed anvial closed 7 years ago

anvial commented 7 years ago

Hello,

I try to set the size of custom widget: addWidget() { const ref: TestWidgetComponent = this.data.dashboard.addItem(TestWidgetComponent); ref.widgetId = this.c2Service.generateUUID(); ref.size = [1, 2]; }

But firstly it renders with default size: @Input() public size: number[] = [1, 1];

And only I move this widget it renders properly.

On add: image image

After moving: image

Thank You.

jaumard commented 7 years ago

Hum maybe it's a bug, I need to investigate more on this, as a quick fix I think you can add this.data.dashboard._calculPositions(); after setting the new size. It should fix the size I think. Let me know. I'll try to fix this soon

anvial commented 7 years ago

Thank You, quick fix gives the expected behaviour.

jaumard commented 7 years ago

Should be ok now on version 1.1.7, use setSize instead of ref.size =...

anvial commented 7 years ago

Yeap, with .setSize it works correctly. Thanks for your work.

diegodbg86 commented 7 years ago

I call to setSize method from inside my custom widget, and it not work. It not update the widget with the new size. Only if i drag de widget, it is updated. This is my code:

`@Component({ selector: 'widget1', templateUrl: '/vistas/widget1.html', providers: [{ provide: WidgetComponent, useExisting: forwardRef(() => Widget1) }] }) export class Widget1 extends WidgetComponent { @Input() public widgetId: string; @Input() public size: number[];

@ViewChild(WidgetHandleDirective) protected _handle: WidgetHandleDirective;

constructor(ngEl: ElementRef, renderer: Renderer2) { super(ngEl, renderer); }

updateSize(width:number, height: number): void { this.setSize([width, height]); }

}`

Can you help me? Thanks, and sorry for my english!

jaumard commented 7 years ago

@diegodbg86 is it a widget that you add dynamically ? I just notice that it doesn't work for widget directly added under <dashboard> tag. I'll try to fix it asap

cyborgdoom commented 7 years ago

if you call this.dashboard.refreshWidgets() after setting the size, it works.

cyborgdoom commented 7 years ago

Hey Also .. never got an answer on a question I posted... is there a way to set the widget sizing based on the content of the widget.... instead of specifying a size of how many rows / columns.

jaumard commented 7 years ago

@cyborgdoom no it's not possible sorry, I only manage specific sizes, you need to calculate this size depending on your widget's content manually to set it

cyborgdoom commented 7 years ago

@jaumard You should add this in as a feature... it would make this a bit more powerful.

jaumard commented 7 years ago

@cyborgdoom I don't need it for my current projects as the content of my widget are all dynamic depending of the size of widgets, not the other way around. And I don't think I will have the time to add this feature, also it can add a lot more complexity to add this mode and also keep the current one as it is

diegodbg86 commented 7 years ago

I add my widgets directly, but I think that I have the same problem if I add dynamically, because I want to update the size within each widget component, not from dashboard component. I think its a good feature to add. Thanks for your work!