getCurrentViewRecords() doesn't seem to work for my grid

Hi Team,

I've have issue with a grid where the rows 'add' seem to work fine but edit gets weird and functions  completely different 
please find my code below and link showing the issue.
https://www.screencast.com/t/GqRw1BcIx1BL

<ejs-grid #mARCCustomTagsGrid id='mARCCustomTagsGrid' [dataSource]='mARCCustomTagsData'
                      [editSettings]='editSettings' [toolbar]='toolbar' (actionComplete)='actionComplete($event)' (actionBegin)='actionBegin($event)'>
                      <e-columns>
                        <e-column field="id" headerText="id" [isPrimaryKey]="true" [visible]=false></e-column>
                        <e-column field="specificationId" headerText="specificationId" [visible]=false></e-column>
                        <e-column field="tag" headerText="Tag" width="10" [validationRules]='tagRules' textAlign='Center'></e-column>
                        <e-column field="subTag" headerText="Sub Tag" width="15" [validationRules]='subTagRules' textAlign='Center'></e-column>
                        <e-column field="constantType" headerText="Constant" width="15" editType='booleanedit' displayAsCheckBox='true' textAlign='Center' [edit]='constantTypeParams' [validationRules]='constantTypeRules'></e-column>
                        <e-column field="constantValue" headerText="Constant Value" width="20" [validationRules]='constantValueRules' textAlign='Center'></e-column>
                        <e-column field="otherFieldType" headerText="Other Field" width="15" editType='booleanedit'  displayAsCheckBox='true' textAlign='Center' [edit]='otherFieldTypeParams'></e-column>
                        <e-column field="fieldName" headerText="Other Field Name" width="20"  editType='dropdownedit' [validationRules]='otherFieldNameRules' [edit]='fieldNamesParams' textAlign='Center'></e-column>
                        <e-column field="sortOrder" headerText="sortOrder" [visible]="false"></e-column>
                      </e-columns>
                    </ejs-grid>
actionComplete(argsany): void {
    if (args.requestType === "add") {
      args.rowData.sortOrder = this.mARCCustomTagsData.length + 1
      args.form[3].parentElement.classList.remove('disablegrid');
      args.form[3].parentElement.classList.remove('wrapper');
    }

    if (args.requestType === 'beginEdit') {
      if (!args.rowData.otherFieldType) {
        args.form[5].parentElement.classList.add('e-disabled');
      }
      else {
        args.form[2].disabled = true;
        args.form[2].parentElement.classList.add('e-disabled');
      }

      if (!args.rowData.constantType) {
        args.form[3].parentElement.classList.add('disablegrid');
        args.form[3].parentElement.classList.add('wrapper');
        args.form[3].value = ''
      }
      else {
        args.form[4].disabled = true;
        args.form[4].parentElement.classList.add('e-disabled');
      }
    }

    if (args.requestType == 'save') {
      localStorage.removeItem(_custom_tag);
      localStorage.removeItem(_is_edit_mode);
    }

    localStorage.setItem(_mARC_CustomTags_DataJSON.stringify(this.mARCCustomTagsGrid.getCurrentViewRecords()));
    this.mARCCustomTagsDataChange.emit(this.mARCCustomTagsGrid.getCurrentViewRecords() as MARCCustomTags[]);
  }

  actionBegin(argsany) {
    if (args.requestType == 'refresh') {
      localStorage.removeItem(_custom_tag);
      localStorage.removeItem(_is_edit_mode);
    }

    if (args.requestType == 'beginEdit') {
      localStorage.setItem(_custom_tagargs.primaryKeyValue);
      localStorage.setItem(_is_edit_mode'true');
    }

    localStorage.setItem(_mARC_CustomTags_DataJSON.stringify(this.mARCCustomTagsGrid.getCurrentViewRecords()));

    if (args.requestType == 'save') {
      let gridInstanceany = (<any>document.getElementById('mARCCustomTagsGrid')).ej2_instances[0];
      args.index = (gridInstance.pageSettings.currentPage * gridInstance.pageSettings.pageSize) - 1;
    }
  }

1 Reply 1 reply marked as answer

AG Ajith Govarthan Syncfusion Team May 4, 2021 05:27 PM UTC

Hi Leela, 

Thanks for contacting Syncfusion support. 

Query: I've have issue with a grid where the rows 'add' seem to work fine but edit gets weird and functions  completely different please find my code below and link showing the issue. 
 
By default in EJ2 Grid the CRUD actions are performed based on the primaryKey value. So, based on your attached code example and video demonstration we found that you have set visible false for the primaryKey column and you also added the data in the Grid component without setting the values for the primarykey column. 

To perform the CRUD actions properly we need the primaryKey value in your Grid application and based on the attached video demo we are not clear about your reported issue so please share the below details to find the root cause of your requirement. 

  1. Have you faced any script error while editing the rows in the Grid component?
 
  1. Please confirm whether editing is not working fine in newly added record or in all records?
 
  1. Have you used remote data in your Grid application?
 
  1. Have you added the primaryKey value somewhere else in your Grid application while adding the rows?
 
  1. Share the syncfusion package version.
 
Regards, 
Ajith G. 


Marked as answer
Loader.
Up arrow icon