Save grid row edit when clicked outside grid

Hello,

After editing a grid row, I need to press enter to save row edit.

Sometime user forget to press enter hence data is not saved.

Is there a way so that user won't have to press enter. As soon as user click somewhere outside grid or focus is outside grid it should save the edit in grid.

Or prompt user to save the row if it is not saved.

Please advise.

Thanks,

Sanjay


2 Replies

NS Nithya Sivaprakasam Syncfusion Team June 24, 2022 06:22 PM UTC

Hi Sanjay,


Greetings from syncfusion support.


Currently, we are validating your query and we will update further details within two business days (28-06-2022).

Until then, we appreciate your patience.


Regards,

Nithya Sivaprakasam.



NS Nithya Sivaprakasam Syncfusion Team June 28, 2022 01:41 PM UTC

Hi Sanjay,


Thanks for your patience.


In Inline Edit, the Grid will automatically save the edited record when you click inside the Grid’s content area. If you click outside of the Grid element, the edited record will not be saved in the Grid. This is the default behavior of Grid.


If you want to save the record when clicking outside of the Grid element, then you need to manually execute the endEdit method to save the data.


endEdit: https://ej2.syncfusion.com/angular/documentation/api/grid/#endedit


We have prepared a sample for your reference. In which we bind the click event to the body element, when you click outside the grid element, we dynamically executed the endEdit method based on the target element.


Load: https://ej2.syncfusion.com/angular/documentation/api/grid/#load


 

[app.component.ts]

 

  load(args) {

    document.body.addEventListener('click', this.bodyClick.bind(this));

  }

  bodyClick(args) {

    // below code executed when click out side of the grid element

    if (args.target.closest('.e-grid') == null && args.target.closest('.e-popup') == null) {

      if (this.grid.isEdit) {

        // save the record if Grid in edit state

        this.grid.endEdit();

      }

    }

  }

 


Sample: https://stackblitz.com/edit/angular-fdmokf?file=app.component.ts,app.component.html


Please get back to us if you need further assistance.


Regards,

Nithya Sivaprakasam.


Loader.
Up arrow icon