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.
Unfortunately, activation email could not send to your email. Please try again.

How can i delete the selected record programmatically?

Thread ID:

Created:

Updated:

Platform:

Replies:

120088 Aug 29,2015 01:44 AM Sep 7,2015 02:58 AM LightSwitch HTML 3
loading
Tags: Grid
Thomas Steschulat
Asked On August 29, 2015 01:44 AM

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


Balaji Marimuthu [Syncfusion]
Replied On August 31, 2015 05:33 AM

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


Thomas Steschulat
Replied On September 4, 2015 12:41 AM

Hello Balaji,
i got it to work.

Thank you for your help!

Regards
Thomas


Balaji Marimuthu [Syncfusion]
Replied On September 7, 2015 02:58 AM

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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;