如何使用模态对话框 Angular 2 编辑 ngxdatatable

用户3431310


  • 我想做的事

    我的ngxdatatable中有办公室名称和部门的列表每个 officename 都有一个编辑和删除按钮,用户可以使用它来编辑和删除 office name/dept。

    对于编辑部分,我希望在单击编辑按钮(链接到编辑功能)时弹出一个模态对话框,并显示办公室名称和部门详细信息。和用户可以编辑办公室名称和/部门保存它。

  • 我所取得的成就

    当用户单击编辑按钮时,我设法让模态对话框弹出。不知何故,将原始值传递给编辑模式对话框时出现问题。

  • 我的问题

    我想将我的原始值传递给模态对话框(处理它)并允许用户编辑 officename/dept 并保存编辑的详细信息。

我的代码,这是我的模态对话框

<div bsModal #editOffice="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-md">
        <div class="modal-content">
            <form [formGroup]="EditOfficeForm" (ngSubmit)="EditOfficeForm.valid && updateOffice(EditOfficeForm.value)" novalidate>

                <div class="modal-header">
                    <button type="button" class="close" (click)="editOffice.hide()" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">Edit Office</h4>
                </div>

                <div class="modal-body">
                    <div class="form-group row">
                        <label class="col-md-3 form-control-label" for="text"> Office Name</label>
                        <div class="col-md-4">
                            <input #officeName type="text" id="officeName" name="officeName" class="form-control" formControlName="officeName" value="{{editingData.officeName}}">
                            <div class='redColor' *ngIf="EditOfficeForm.controls.officeName.touched">
                                <div *ngIf="EditOfficeForm.controls.officeName.hasError('required')">
                                    Required.
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-md-3 form-control-label" for="text"> Date </label>
                        <div class="col-md-4">
                            <input #dept type="text" id="dept" name="dept" class="form-control  ng-pristine ng-valid ng-touched"
                                formControlName="dept" value="{{editingData?.dept}}">
                            <div class='redColor' *ngIf="EditHolidayForm.controls.dept.touched">
                                <div *ngIf="EditHolidayForm.controls.dept.hasError('required')">
                                    Required
                                </div>
                            </div>
                        </div>
                    </div>   

                    <button type="button" class="btn btn-space pull-right" (click)="editOffice.hide()" aria-label="Close"> Cancel </button>&nbsp;
                    <button class='btn btn-primary' type='submit' (click)="editOffice.hide()" [disabled]='!EditOfficeForm.valid'>Submit</button>

                    <br>

                </div>

            </form>
        </div>
    </div>
</div>

我的组件文件

export class OfficeComponent {

    @Output() public rowEdited: EventEmitter<any> = new EventEmitter();
    public editingData:EditingRowData;

    EditOfficeForm: FormGroup;
    officename: FormControl;
    dept:FormControl;

    constructor(private fb: FormBuilder, public http: Http, private dataService: DataService) {

        this.EditOfficeForm= fb.group({
            officename: this.officename,
            dept:this.dept
        })

    }

    ngOnInit() {
        this.getAllOffice();
    }

    getAllOffice()
    {
        /// getting all officefrom service
    }

    editOffices(rowDetails:any): void
    {
        this.rowEdited.emit({rowDetails});
        console.log('row details', { rowDetails });

        //SEND THIS VALUE TO POPUP DIALOG  

        this.editingData = rowDetails
        // this.editingData contain ALL THE SELECTED OFFICENAME AND DEPT DETAILS. 
        // SO I WANT TO DISPLAY THIS DATA IN MY MODAL DIALOG HTML.


    }

    updateOffice(value: Object): void {
        //updating and passed to database
    } 
}

我一直未定义 officename,我尝试使用editingData?officename它,它开始显示在我的模式对话框中。但是,假设用户只编辑 officename 并保留 dept 作为原始数据,那么它捕获的值是{officename:"newOfficename", dept:null}

因此,我希望正确编辑和保存详细信息。

如果用户只编辑一个(办公室名称/部门),则只应更改该一个,而其余数据保持不变。

朱莉娅·帕辛科娃

选择一行以进行编辑时,您可能必须使用eDitingData修补EditOfficeform FormGroup。类似的东西:

this.EditOfficeForm.patchValue(this.editingData);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Angular 2及更高版本中实现模态对话框

如何在Angular 2中获取带有模态对话框条件的元素?

Angular2-MaterializeCSS:模态对话框无法打开

如何使用 angular 9 中的 Angular 材质制作持久对话框(模态框)?

如何使用angular2材质对话框阻止canDeactivate

Angular2:模态对话框不捕捉关键事件

在Angular 2+的模态中嵌入的对话框前面显示mat-select

Angular2-不将数据传递给模态对话框

带有PrimeNG的Angular 2嵌套模态对话框不起作用

如何立即关闭所有使用angular-materiel打开的模态对话框

Angular 2.0和模态对话框

无法使用Teststack / White在模态/对话框中的编辑字段中输入文本

如何编辑Android对话框标题

如何编辑对话框文本

如何将模态提交给控制器并在模态对话框中关闭编辑后刷新ajax

如何自动滚动到material2 angular2对话框的顶部?

使用对话框编辑单击时编辑Listview项

如何从Angular打开输入type =“ file”对话框-ng2FileUpload

如何从angular-material2对话框与其父级进行通信

Angular2 - 如何将对话框滚动到顶部

使用angular2 @HostListener时onbeforeunload确认对话框不显示

Angular2材质对话框css,对话框大小

如何使用Angular 4对话框指令?

如何使用 Angular 关闭多个对话框

摆脱Angular Material模态对话框周围的空白

Angular 11 中的非模态对话框

Angular2材质对话框自动关闭

Angular 2进行确认对话框的简单方法

Angular 2材质:动态自定义对话框