question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gridster within md-tabs

See original GitHub issue

Hi again. I have the following code here:

`<md-tab-group [dynamicHeight]=“true” [selectedIndex]=“selectedDashboard” (selectChange)=“onTabChange($event)” [dynamicHeight]=“true”> <md-tab *ngFor=“let dashboard of dashboards; let i = index;” >

    <ng-template md-tab-label>
      {{dashboard.title}}
    </ng-template>

          <gridster [options]="gridsterOptions" [draggableOptions]="gridsterDraggableOptions" #gridster>
            <gridster-item [(x)]="widget.x" [(y)]="widget.y" [(w)]="widget.w" [(h)]="widget.h" *ngFor="let widget of dashboards[selectedDashboard].widgets">
              <!-- your content here -->

              <md-toolbar class="panel-heading" color="">
                {{widget.title}}
              </md-toolbar>

              <verso-notification class="panel-body" *ngIf="widget.type == 'notification'"></verso-notification>
              <verso-target class="panel-body" *ngIf="widget.type == 'target'"></verso-target>
              <verso-topic class="panel-body" *ngIf="widget.type == 'topic'"></verso-topic>
              <verso-note class="panel-body" *ngIf="widget.type == 'note'"></verso-note>
              <verso-task class="panel-body" *ngIf="widget.type == 'task'"></verso-task>
              <verso-kpi class="panel-body" *ngIf="widget.type == 'kpi'"></verso-kpi>

            </gridster-item>
          </gridster>


  </md-tab>
</md-tab-group>`

There is a strange offset between the mouse and gridster-item when I put gridster in md-tab. imageedit_6_8950083445

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
speculeescommented, May 27, 2017

I have had success with this approach. Try this…

In gridster-item.component :

`const dragStartSub = draggable.dragStart.subscribe((event: DraggableEvent) => { this.zone.run(() => { this.gridster.onStart(this.item); this.isDragging = true; cursorToElementPosition = event.getRelativeCoordinates(this.$element, event); }); });

const dragSub = draggable.dragMove.subscribe((event: DraggableEvent) => { this.$element.style.top = (event.clientY - cursorToElementPosition.y) + ‘px’; this.$element.style.left = (event.clientX - cursorToElementPosition.x) + ‘px’; this.gridster.onDrag(this.item); });`

And in DraggableEvent.ts replace :

'getRelativeCoordinates(container: HTMLElement, event: DraggableEvent): { x: number, y: number } { let style = window.getComputedStyle(container, null); return { x: event.clientX - parseInt(style.getPropertyValue(“left”), 10), y: event.clientY - parseInt(style.getPropertyValue(“top”), 10) }; }`

off course the event.getRelativeCoordinates(…) now has to be adjusted in prototype and so on…

0reactions
speculeescommented, Jul 28, 2017

Problem is fixed. Good job sir. 👍 However, sometimes the data that is passed to the parent component (tab) initially takes time to load so I guess the child component (gridster) doesn’t take that into account and takes the wrong size of the parent. But, perhaps that is not a problem of gridster so much as a tab problem. And it is easily fixed with something like <md-tabs ngIf=“dataExists” … > stuff. So, all okay on my end. 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Gridster in Multiple Tab? - Stack Overflow
I want to create multiple dashboards using using angular-gridster2 in angular 8. I have multiple tabs having gridster in each Tab.
Read more >
Petargitnik - Example Material Tab With Gridster2 - StackBlitz
This is an example repo of material tab used with angular-gridster2.
Read more >
Angular Gridster Tabs - JSFiddle - Code Playground
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
Read more >
Angular 지시문 및 서버 요청 (Angular directives and server ...
I'm just wondering is it a good practice to make http GET request to fetch data inside an angular directive? Directive's behavior is...
Read more >
Prevent tab change event in angular material md-tab
Issue. Is it possible to prevent tab change in angular-material's md-tabs or md-tab directive? I use the md-on-select directive to execute a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found