Nemanja Andric
Nemanja Andric

Reputation: 665

Syncfusion Angular Grid - delete selected row

I have simple grid: 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'];
  }

Catch action complete:

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);
      }
    }
  }

Problem is that when I select a row and click on delete, every time is removed the first row from the grid. But when I refresh the page, I received good data. I confusing is that I receive List of data on the delete button. But when I click on Add, Update, Cancel I receive clean model. Why delete button is different and what is a root of the problem?

enter image description here

Upvotes: 1

Views: 1954

Answers (1)

Madhu
Madhu

Reputation: 2551

Seems like the primary key column is not specified in grid. The edit and delete operations need primary key field to identify the record/row. Please refer to the below link.

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

Upvotes: 2

Related Questions