Syncfusion Angular Grid-删除选定的行

时间:2018-12-17 13:55:08

标签: angular syncfusion

我有简单的网格: enter image description here

  GridSettings() {
    this.editSettings = { allowAdding: true, allowEditing: true, allowDeleting: true, showConfirmDialog: true, showDeleteConfirmDialog: false, };
    this.searchOptions = { fields: ['SoftwareSystem', 'LicenseComponentId', 'Notes'], operator: 'contains', ignoreCase: true };
    this.pageSettings = { enableQueryString: true, pageSize: 20 };
    this.filterSettings = { type: "Menu" };
    this.filter = { type: "CheckBox" };
    this.editparams = { params: { popupHeight: '300px' } };
    this.formatoptions = { type: 'dateTime', format: 'M/d/y hh:mm a' }
    this.toolbar = ['Add', 'Edit', 'Delete', 'Update', 'Cancel'];
  }

捕获动作完成:

actionComplete(args: EditEventArgs) {
    if (!isNullOrUndefined(args) && !isNullOrUndefined(args['data'])) {
      let itemToSave = args['data'] as SiteLicenceAllocation;
      if (this.licenseObj != undefined && this.licenseObj.value != null)
        itemToSave.LicenseComponentId = this.licenseObj.value.toString();

      if (args.requestType == 'add') {
        itemToSave.SiteId = this.selectedSite.SiteId;
        itemToSave.ObjectState = ObjectStateType.Created;
      }

      else if (args.requestType == 'delete') {
        itemToSave[0].ObjectState = ObjectStateType.Deleted;
        this.saveLicence(itemToSave[0]);
      }

      else if (args.requestType == 'save') {
        if (itemToSave.ObjectState == undefined)
          itemToSave.ObjectState = ObjectStateType.Updated;

        this.saveLicence(itemToSave);
      }
    }
  }

问题是,当我选择一行并单击删除时,每次都会从网格中删除第一行。但是,当我刷新页面时,我收到了很好的数据。我感到困惑的是,我在删除按钮上收到了数据列表。但是,当我单击添加,更新,取消时,我收到干净的模型。为什么删除按钮不一样?问题的根源是什么?

enter image description here

1 个答案:

答案 0 :(得分:1)

似乎未在网格中指定主键列。编辑和删除操作需要主键字段来标识记录/行。请参考下面的链接。

https://ej2.syncfusion.com/angular/documentation/grid/edit/#troubleshoot-editing-works-only-for-the-first-row https://ej2.syncfusion.com/angular/documentation/grid/edit/