We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How can i delete the selected record programmatically?

I'm using a delete Button in a grid column:

      fieldname[i] = {
        headerText: "Aktionen",
        commands: [
            { type: ej.Grid.UnboundType.Edit, buttonOptions: { contentType: "imageonly", prefixIcon: "e-edit", click: "wiutils.editclick", gridname: gridname, editscreenname: editscreenname } },
            { type: ej.Grid.UnboundType.Delete, buttonOptions: { contentType: "imageonly", prefixIcon: "e-delete", click: "wiutils.deleteclick", gridname: gridname, entityname: contentItem.model.dataSource.member.name } }
        ],
        isUnbound: true,
        width: 70
      };

I'm using custom properties "gridname: gridname, entityname: contentItem.model.dataSource.member.name" to send relevant objects or data to the deleteclick function to find out what i can do to solve my problem.
This is only the actual code. 

looks like this: screenshot



i want the user to confirm deletion: screenshot2

so i wrote my own click event:
.... click: "wiutils.deleteclick" ....

Code (actual, after Hours of trying to find out how to delete a record from the grid and database programmatically)
  var deleteclick = (function (sender)
  {
    var gridObj = $("#" + sender.model.gridname).ejGrid('instance');

    msls.showMessageBox("Wollen Sie den Datensatz wirklich löschen?", { buttons: msls.MessageBoxButtons.yesNo }).then(function (result)
    {
      if (result === msls.MessageBoxResult.yes)
      {
        // Delete selected record
       
       QUESTION: How con i delete the selected record?

        myapp.applyChanges().then(null, function fail(e)
        {
          // If error occurs, show the error.
          msls.showMessageBox(e.message, { title: e.title }).then(function ()
          {
            // Discard Changes
            screen.details.dataWorkspace.wasteitData.details.discardChanges();
          });
        });
      }
      else if (result === msls.MessageBoxResult.no)
      {
        toastr.info("Löschvorgang abgebrochen.");
      }
    });
    gridObj.refreshContent(true);
  });

Are there any other ways to confirm deletion?
or
What must i do to delete the selected record in my deleteclick function?
or
am i totally wrong and must go any other way to accomplish my goal?

Kind regards
Thomas


3 Replies

BM Balaji Marimuthu Syncfusion Team August 31, 2015 09:33 AM UTC

Hi Thomas,


Thanks for using Syncfusion Products.


The delete operation was performed by using the deleteSelected method and the selected record get by using getSelectedRecords method in Grid. 


Please refer to the following Help document for getSelectedRecords,

http://helpjs.syncfusion.com/js/api/ejgrid#methods:getselectedrecords


In actionBegin event, we have deleted the selected record by passing the selected record values to the selectedItem.


Please refer to the sample and code example as below,

Sample: local-lightswitch



itemTemplate.ejGrid(

        {

            dataSource: contentItem.value.data,

            actionBegin: function (args) {

                if (args.requestType == "delete") {

                    contentItem.value.selectedItem = this.getSelectedRecords()[0];

                    contentItem.value.deleteSelected(); //delete the records in grid

                    myapp.applyChanges();

                }

            },

            . . .


                    });


To Display the confirm message box when deleting the records in Grid, we suggest you to enable the showDeleteConfirmDialog property. Please refer to below code example and Help document,


itemTemplate.ejGrid(

        {

            dataSource: contentItem.value.data,

            editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, showDeleteConfirmDialog: true },

            },


            . . .


                    });


<style>

        .e-grid .e-dialog .e-buttons{

            float:none;

        }

        .e-grid .e-dialog .e-btn-mini{

            width:100%;

            height:100%;

        }

    </style>


Help Document http://helpjs.syncfusion.com/js/api/ejgrid#members:editsettings-showdeleteconfirmdialog



Regards,

Balaji Marimuthu



TS Thomas Steschulat September 4, 2015 04:41 AM UTC

Hello Balaji,
i got it to work.

Thank you for your help!

Regards
Thomas



BM Balaji Marimuthu Syncfusion Team September 7, 2015 06:58 AM UTC

Hi Thomas,

We are happy that the provided suggestion helped you.

Please get back to us if you need any further assistance. 

Regards,

Balaji Marimuthu


Loader.
Live Chat Icon For mobile
Up arrow icon