brunano21 / angular-4-data-table

An Angular 5 data table, with pagination, sorting, expandable rows, row selection, etc. with basic accessibility support.
MIT License
11 stars 19 forks source link

Can we edit row in angular-5-datatable? #39

Closed prakashkaruppiah closed 6 years ago

prakashkaruppiah commented 6 years ago

Hi @brunano21 , Can we edit row in angular-5-datatable? Please help us.

brunano21 commented 6 years ago

What do you mean by edit?

prakashkaruppiah commented 6 years ago

Like grid cells editing, we did cell editing to angular 4 data table using input box, but its shows input box always. We need, when we click that cell, then only show edit mode input box. Code
<data-table-column [property]="'ReceicedQty'" [header]="'Received Qty'" [sortable]="true" [resizable]="true" [width]="90"> <ng-template #dataTableCell let-item="item"> <input type="number" name="ReceicedQty"[(ngModel)]="item.ReceicedQty" (change)="onSelectRecQty(item.ReceicedQty,item.GRN_Recpt_Id,item)" [ngModelOptions]="{standalone: true}" class="form-control input-sm" style="width: 75px;" />

brunano21 commented 6 years ago

You could bind a click event to the cell and swap the content with an input field within the bound function. Does this fix your issue?

prakashkaruppiah commented 6 years ago

Can you give me some example code?

brunano21 commented 6 years ago

@prakashkaruppiah are you still interested in this?

prakashkaruppiah commented 6 years ago

yes @brunano21 , Please give me suggestion.

brunano21 commented 6 years ago

component.html:

<data-table-column 
   [property]="ReceicedQty"
   [header]="Received Qty" 
   [sortable]="true" [resizable]="true" [width]="90">
   <ng-template #dataTableCell let-item="item" let-row="row">
      <div (click)="toggleEdit(item, row)">
         <span *ngIf="!item.edit" [textContent]="item.ReceicedQty"></span>
         <input *ngIf="item.edit" type="number" name="ReceicedQty" [(ngModel)]="item.ReceicedQty" 
            (change)="onSelectRecQty(item.ReceicedQty,item.GRN_Recpt_Id,item)"
            [ngModelOptions]="{standalone: true}" class="form-control input-sm" style="width: 75px;" />
      </div>

component.ts:

...
toggleEdit(item, row) {
   item.edit = !item.edit;
}
...