Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 剑道UI网格与角度2。每行1个编辑按钮,而不是多个编辑按钮_Angular_Kendo Grid - Fatal编程技术网

Angular 剑道UI网格与角度2。每行1个编辑按钮,而不是多个编辑按钮

Angular 剑道UI网格与角度2。每行1个编辑按钮,而不是多个编辑按钮,angular,kendo-grid,Angular,Kendo Grid,我希望在网格底部有一个编辑按钮,而不是每个按钮都有一个编辑按钮,只有在对所有可编辑列进行更改后才会触发该按钮。在Angular 2中有没有办法做到这一点?我不希望用户必须为每一行单击“编辑”,进行更改,然后移动到下一行,单击“编辑”,然后再次进行更改 import { Observable } from 'rxjs/Rx'; import { Component, OnInit, Inject } from '@angular/core';

我希望在网格底部有一个编辑按钮,而不是每个按钮都有一个编辑按钮,只有在对所有可编辑列进行更改后才会触发该按钮。在Angular 2中有没有办法做到这一点?我不希望用户必须为每一行单击“编辑”,进行更改,然后移动到下一行,单击“编辑”,然后再次进行更改

            import { Observable } from 'rxjs/Rx';
            import { Component, OnInit, Inject } from '@angular/core';
            import { FormGroup, FormControl, Validators } from 
            '@angular/forms';

            import { GridDataResult } from '@progress/kendo-angular-grid';
            import { State, process } from '@progress/kendo-data-query';

            import { Product } from './model';
            import { EditService } from './edit.service';

            @Component({
                selector: 'my-app',
                template: `
                  <kendo-grid
                      [data]="view | async"
                      [height]="533"
                      [pageSize]="gridState.take" [skip]="gridState.skip" 
                [sort]="gridState.sort"
                      [pageable]="true" [sortable]="true"
                      [selectable]="true"
                      (dataStateChange)="onStateChange($event)"
                      (edit)="editHandler($event)" 
                (cancel)="cancelHandler($event)"
                      (save)="saveHandler($event)" 
                (remove)="removeHandler($event)"
                      (add)="addHandler($event)"
                    >
                    <!--<ng-template kendoGridToolbarTemplate>
                        <button kendoGridAddCommand>Add new</button>
                    </ng-template> -->
                    <kendo-grid-column field="ProductName" title="Product 
                    Name" [editable]="false"></kendo-grid-column>
                    <kendo-grid-column field="UnitPrice" editor="numeric" 
                    title="Price"></kendo-grid-column>
                    <kendo-grid-column field="Discontinued" editor="boolean" 
                     title="Discontinued"></kendo-grid-column>
                    <kendo-grid-column field="UnitsInStock" editor="numeric" 
                     title="Units In Stock" [editable]="false"></kendo-grid-
                    column>
                    <kendo-grid-command-column title="command" width="220">
                        <ng-template kendoGridCellTemplate let-
                    isNew="isNew">
                            <button kendoGridEditCommand class="k-
                    primary">Edit</button>
                            <button kendoGridRemoveCommand>Remove</button>
                            <button kendoGridSaveCommand 
                    [disabled]="formGroup?.invalid">{{ isNew ? 'Add' : 
                    'Update' }}</button>
                            <button kendoGridCancelCommand>{{ isNew ? 
                      'Discard changes' : 'Cancel' }}</button>
                        </ng-template>
                    </kendo-grid-command-column>
                  </kendo-grid>
              `
            })
            export class AppComponent implements OnInit {
                public view: Observable<GridDataResult>;
                public gridState: State = {
                    sort: [],
                    skip: 0,
                    take: 10
                };
                public formGroup: FormGroup;

                private editService: EditService;
                private editedRowIndex: number;

                constructor( @Inject(EditService) editServiceFactory: any) {
                    this.editService = editServiceFactory();
                }

                public ngOnInit(): void {
                    this.view = this.editService.map(data => process(data, 
                this.gridState));

                    this.editService.read();
                }

                public onStateChange(state: State) {
                    this.gridState = state;

                    this.editService.read();
                }

                protected addHandler({ sender }: any) {
                    this.closeEditor(sender);

                    this.formGroup = new FormGroup({
                        'ProductID': new FormControl(),
                        'ProductName': new FormControl("", 
                    Validators.required),
                        'UnitPrice': new FormControl(0),
                        'UnitsInStock': new FormControl("", 
                    Validators.compose([Validators.required, 
                    Validators.pattern('^[0-9]{1,2}')])),
                        'Discontinued': new FormControl(false)
                    });

                    sender.addRow(this.formGroup);
                }

                protected editHandler({ sender, rowIndex, dataItem }: any) {
                    //protected editHandler({ sender, rowIndex, dataItem }){
                    this.closeEditor(sender);

                    this.formGroup = new FormGroup({
                        'ProductID': new FormControl(dataItem.ProductID),
                        'ProductName': new FormControl(dataItem.ProductName, 
                    Validators.required),
                        'UnitPrice': new FormControl(dataItem.UnitPrice),
                        'UnitsInStock': new 
                    FormControl(dataItem.UnitsInStock, 
                    Validators.compose([Validators.required, 
                    Validators.pattern('^[0-9]{1,2}')])),
                        'Discontinued': new 
                    FormControl(dataItem.Discontinued)
                    });

                    this.editedRowIndex = rowIndex;

                    sender.editRow(rowIndex, this.formGroup);
                }

                protected cancelHandler({ sender, rowIndex }: any) {
                    this.closeEditor(sender, rowIndex);
                }

                private closeEditor(grid: any, rowIndex = 
                this.editedRowIndex) {
                    grid.closeRow(rowIndex);
                    this.editedRowIndex = undefined;
                    this.formGroup = undefined;
                }

                protected saveHandler({ sender, rowIndex, formGroup, isNew 
                }: any) {
                    const product: Product = formGroup.value;

                    this.editService.save(product, isNew);

                    sender.closeRow(rowIndex);
                }

                protected removeHandler({ dataItem }: any) {
                    this.editService.remove(dataItem);
                }
            }
从'rxjs/Rx'导入{Observable};
从“@angular/core”导入{Component,OnInit,Inject};
从导入{FormGroup,FormControl,Validators}
“@angular/forms”;
从“@progress/kendo angular grid”导入{GridDataResult};
从'@progress/kendo data query'导入{State,process};
从“./model”导入{Product};
从“./edit.service”导入{EditService};
@组成部分({
选择器:“我的应用程序”,
模板:`
编辑
去除
{{是否新建?'Add':
'更新'}}
{{是新的吗?
“放弃更改”:“取消”}
`
})
导出类AppComponent实现OnInit{
公众观点:可见;
公共网格状态:状态={
排序:[],
跳过:0,
拍摄时间:10
};
公共formGroup:formGroup;
私有editService:editService;
私有editedRowIndex:编号;
构造函数(@Inject(EditService)editServiceFactory:any){
this.editService=editServiceFactory();
}
public ngOnInit():void{
this.view=this.editService.map(数据=>process(数据、,
这个国家),;
这个.editService.read();
}
公共状态更改(状态:状态){
this.gridState=state;
这个.editService.read();
}
受保护的addHandler({sender}:any){
这个.closeEditor(发送方);
this.formGroup=新的formGroup({
“ProductID”:新的FormControl(),
“ProductName”:新的FormControl(“,
验证器。必需),
“单价”:新的FormControl(0),
“UnitsInStock”:新的FormControl(“,
组合([Validators.required),
模式('^[0-9]{1,2}')),
“已终止”:新FormControl(false)
});
sender.addRow(this.formGroup);
}
受保护的editHandler({sender,rowIndex,dataItem}:any){
//受保护的editHandler({sender,rowIndex,dataItem}){
这个.closeEditor(发送方);
this.formGroup=新的formGroup({
“ProductID”:新的FormControl(dataItem.ProductID),
“ProductName”:新FormControl(dataItem.ProductName,
验证器。必需),
“单价”:新的FormControl(dataItem.UnitPrice),
“UnitsInStock”:新
FormControl(dataItem.UnitsInStock,
组合([Validators.required),
模式('^[0-9]{1,2}')),
"停产":新
FormControl(数据项。已停止)
});
this.editedRowIndex=行索引;
sender.editRow(行索引,this.formGroup);
}
受保护的cancelHandler({sender,rowIndex}:any){
此.closeEditor(发送方,行索引);
}
专用closeEditor(网格:任意,行索引=
此.editedRowIndex){
grid.closeRow(行索引);
this.editedRowIndex=未定义;
this.formGroup=未定义;
}
受保护的saveHandler({sender,rowIndex,formGroup,isNew
}:任何){
const product:product=formGroup.value;
this.editService.save(产品,isNew);
sender.closeRow(行索引);
}
受保护的removeHandler({dataItem}:any){
this.editService.remove(数据项);
}
}

你的代码是什么样子的?看起来是这样的:哈哈哈..更新到post。发布问题之前请阅读。抱歉,这是一个新问题,只是用代码重新发布。你的代码是什么样子的?看起来是这样的:哈哈哈..更新到post。发布问题之前请阅读。抱歉,这是一个新问题,只是用代码重新发布