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
Drag and Drop with MatTable #13770
Comments
Not to muddy the water, but this line of your StackBlitz solved an issue I was having with the previousIndex of the CdkDragDrop event (thanks btw!): Is there a known issue with event.previousIndex when used with MatTable? |
Glad to help :) |
I'm also trying to implement drag and drop reorder in my material table and I'm having the same issue. Does anyone have a working example of it ? By the way, I feel like this is a rather standard use case (drag and drop reorder in a material table). Wouldn't it make sense to have a working example of it in the angular material documentation about drag and drop ? |
@antoine-le-maire I implemented it, the problem was with the dragPreview. The solution is to implement ( remake ) the actual design of the row, because the styles were not applied by default. |
I think there are 2 problems around the table + drag and drop, both reproduced by the stackblitz above :
I believe you're talking about the 2nd problem here right ? If so, how did you re-design the row ? Did you read the width of each column in the dom to force it to the dragged element (jquery style) ? |
@antoine-le-maire did you find a solution to make cdkDragHandle work with the mat-table? |
@antoine-le-maire @henry-phelps-ascendlearning-com The workaround with the drag handle is to make the whole row dragable, then with css add |
I did not find a solution, I had to let the whole row draggable. This is acceptable for now but this is a problem if you want to select text in the row for example. |
I got it to work using @samir-h suggestion. Here is an example: https://stackblitz.com/edit/angular-8tmeav . See lines 14 and 39 of app.component.html |
Ah, sorry I was thinking about reordering the table columns. It did basically the same, using the See https://stackblitz.com/edit/angular-cc77j7 . I can move the headers, but it doesn't even trigger the drop event afterwards. When moving the |
@samir-h, Do you have an example of redesigning the row so the styles apply? I'm currently having that issue. |
@eliskaachee Use the
|
@samir-h Your suggestion to add the "pointer-events: none" to the mat-row helped me solve the issue. But my table also has an Input. By making the Pointer events none I'll not be able to use Input. |
Come cross with drag and drop for the angular material table. |
Here is demo: https://stackblitz.com/edit/angular-p12rek |
Thank you for this! For anyone having trouble, I had to use .mat-cell instead of .cell to get the styles applied:
|
It's not acceptable to set |
I have achieved that UX by applying Documentation of cdkDragRootElement is here. Only remaining problem is |
It would be nice if |
So I ran across dealing with the drag handle situation recently on a project and while I think we should be able to use the dragHandle directive in a column def nothing I tried or from what I can tell nothing that others have tried have really worked. @samir-h is right the pointer events do work however the UX is wrong for various reasons. This lead me to thinking that maybe there is a solution for now if we approach it a different way and here is what I came up with. I start the table with Then on the drag handle element I want to use I use I have created a demo with the materials basic table example and just added the drag and drop to that on stack blitz here |
I have two cdkDropList, one on MatTable and the 2nd is a chip list. Dragging a chip to a table row (in a different component altogether) result in what appears to b a bug: the dragged chip is "stuck" on the 1st row that was dragged over, and the placeholder stays in place when dragging to another table row. |
This was almost a perfect solution for me. The only outstanding issue is that I can no longer scroll the page by swiping this list using touch. It actually works somewhat intermittently but I can't understand why. Every 2nd or 3rd scroll swipe seems to take |
The example https://stackblitz.com/edit/angular-p12rek from above does not work with angular 8.2.5 (probably also versions after that) and tsconfig.json angularCompilerOptions.enableIvy = true. It looks like the cdkDropList* attributes are missing, you can drag the column header around the whole page. |
Had the same issue regarding table cells and assigning a drag handle. My workaround was to add a directive to non-draggable table cells in the draggable row that cancels bubbling of the I believe the following solution is better when you need interactivity within the cells. In that case, the css solution ( Please see my StackBlitz here: https://stackblitz.com/edit/angular-tgrcni Here is a related StackOverflow: https://stackoverflow.com/questions/55028318/how-to-make-a-mat-table-row-drag-drop-work-with-cdkdraghandle-so-that-the-row-is/58828917#58828917 Hope this helps. |
Démo online: https://stackblitz.com/edit/angular-hrulnj |
To solve it on my component I first added drags and handles references:
then on
Here is the demo implemented |
@rosostolato Your code doesn't work. @jadekler the I've kind of narrowed in on the issue. |
@Falven did you check the demo that I adjusted? It's working correctly and I even use it in my projects. |
@jadekler Thanks! |
I'm definitely not very knowledageable about npm/nodejs, but I think you can clone components to your local machine and then use npm link to force npm to use it instead of a remote copy. But, yeah, never done any of that myself, so I might be totally wrong! :) |
Each commit to master is published to https://github.com/angular/cdk-builds and https://github.com/angular/material2-builds. |
@crisbeto Thanks for that!
In |
@crisbeto is this issue ready to be closed, now that angular/material.angular.io#727 is in? |
Closing since the related PR has been merged in. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug, feature request, or proposal:
Feature request
What is the expected behavior?
Drag and drop with a drag handle and MatTable
What is the current behavior?
The drag handle is not being found. The ContentChildren on CdkDrag doesn't get it.
What are the steps to reproduce?
StackBlitz https://stackblitz.com/edit/angular-igmugp
What is the use-case or motivation for changing an existing behavior?
If the drag handle could be found, we could use drag and drop using a handle with a table
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular 7.0.0
Angular Material 7.0.1
The text was updated successfully, but these errors were encountered: