Inline text editing with Mat-table:

五迷三道 提交于 2021-02-18 17:52:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!