Clear row contents in Edit Mode and Delete row on command click in View Mode

Hi Team,

I am working on a requirement where I have added command column to the grid with clear button. I am supposed to clear row data if the row is in edit mode and Delete row if the row is in view mode.

I am adding an example where we can add a new row by selecting item code.



Please let me know how to achieve this requirement.

Regards,
Cyril Ovely


Attachment: clearRowWithCommandClick_4c1c9d81.zip

3 Replies

PS Pavithra Subramaniyam Syncfusion Team May 2, 2022 01:34 PM UTC

Hi Cyril,


Thanks for contacting Syncfusion support.


From your update, we understood that you want to perform actions while clicking the “clear” button based on the Grid edit mode. If yes, you can find whether the current row is an editable row or not by searching for the rows containing the “e-addedrow” or “e-editedrow” class. If it is in edit mode, you can clear the values in the current row editors by setting the default values just like you did for the “ItemCode” select action. If it is in view mode, you can delete the row by using the “deleteRecord” method. Please refer to the below code example and API link for more information.


 commandClick: function (args) {

  .  .  .

  if (args.commandColumn && args.commandColumn.type === "Clear") {

 

    if (args.target.closest(".e-addedrow") || args.target.closest(".e-editedrow")) {

      // Clear Row data if row is in Edit mode

      let ItemDescription =

        gridInst.editModule.formObj.element.querySelector(

          "#" + "ItemDescription"

        );

      ItemDescription.value = "";

      // Need to set the empty string null or required values for all editors just as the above

      .  .  .

 

    } else {

      // Delete Row if row is in View mode

 

      this.$refs.SO_lineItem_Grid.ej2Instances.deleteRecord("ItemCode", args.rowData["ItemCode"]);

    }

  }

},

 


API: https://ej2.syncfusion.com/vue/documentation/api/grid/#deleterecord


Please get back to us if you need further assistance on this.


Regards,

Pavithra S



CO Cyril Ovely May 2, 2022 06:30 PM UTC

Hi Pavitra S,

Thanks for your reply. Adding to your solution I have added allowDeleting: true   property in editSettings to make it work.

Regards,
Cyril Ovely



PS Pavithra Subramaniyam Syncfusion Team May 3, 2022 04:53 AM UTC

Hi Cyril Ovely,

 

It is great to hear that the provided solution helps you!


Please get back to us if you need further assistance.


Regards,

Pavithra s



Loader.
Up arrow icon