问题
Does anyone have a good solution to adding inline text editing to a column where you can edit and save and re-edit with mat table like in this example: https://material.io/design/components/data-tables.html#behavior it look like it's still an open issue on gitHub: https://github.com/angular/material2/issues/5982
回答1:
inside your matColumnDef you should have a <th></th>
and a <td></td>
, simply add input to the <td></td>
with reactive forms.
if you wish it to be practically the same as the material example, you could create a position absolute element inside a positioned-relative element inside the that would propmt on click, receive and input, and close after some logic, to update the formControl.
Still, you'd need formControls, and to edit the matColumnDef.
example taken from the link of the github request
<ng-container matColumnDef="time">
<th mat-header-cell *matHeaderCellDef> time </th>
<td mat-cell *matCellDef="let element; let i = index" [formGroupName]="i">
<input type="text" formControlName="time" placeholder="Time">
</td>
</ng-container>
回答2:
The git hub issue you mentioned has a few implementations people have come up with.
You can get inspiration from this:
https://stackblitz.com/edit/material2-beta12-es19ub?file=app%2Fapp.component.html
or this: https://stackblitz.com/edit/angular-g5u7cy?file=app%2Ftable-editing-example.html
I would go through the github issue to see the different options people have come up with.
来源:https://stackoverflow.com/questions/55267769/inline-text-editing-with-mat-table