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.

Common delete script for every MVC grid

Thread ID:

Created:

Updated:

Platform:

Replies:

114921 Dec 13,2013 10:40 AM Dec 16,2013 01:32 AM ASP.NET MVC (Classic) 2
loading
Tags: Grid
Yulia Klimov
Asked On December 13, 2013 10:40 AM

I have implemented the suggestion from this site where we delete the record from the grid.

In the view:

@(Html.Syncfusion().Grid<CDM.CoreData.Lookup.LkBase>("lookupGrid")
.....
.....

@(Html.Syncfusion().Dialog("lookupDeleteDialog").MinHeight(10).Height(80).Modal(true).AutoOpen(false))

<div class="Status" style="color: red; font-family: 'Times New Roman'">

</div>

<div id="lookupDeleteDialog" title="Delete Lookup Confirmation" style="display: none">

Are you sure you want to delete the record?

<input type="button" id="confrimLookupDelete" value="Delete" />

<input type="button" id="cancelLookupDelete" value="Cancel" />

</div>

And my script is

//Deleting a record from a grid

window.confirmed = false;

function deleteConfirmation(sender, args) {

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

if (currentLookupData.IsDefault == true) {

$(".Status").html("'" + currentLookupData.Value + "' is the Default value, so it can not be deleted.");

args.cancel = true;

}

else {

$("#lookupDeleteDialog").dialog("open");

if (!window.confirmed)

args.cancel = true; // Deletion operation is cancelled to prevent automatic deletion before confirmation

window.confirmed = false;

countLookups = sender._totalRecordsCount;

}

}

}

 

$(document).ready(function () {

$("#confrimLookupDelete").click(function () {

var da = $find('lookupGrid');//To get the Grid Object

window.confirmed = true //It is set to true to perform the deletion when delete request is sent from confirm button

gridObj.sendDeleteRequest(); //Delete Request is sent when confirm button is clicked

$("#lookupDeleteDialog").dialog("close");

});

$("#cancelLookupDelete").click(function () {

$("#lookupDeleteDialog").dialog("close");

});

});

It works fine, however I want it to  be used for each grid in my project, therefore I need to have a way to dynamically call that grid in the script (in place of var da = $find('lookupGrid'))

I have tried to use var gridObj = $find('.Syncfusion-Grid-Core') but it returns a null object. What do you suggest?

 


Yulia Klimov
Replied On December 13, 2013 11:15 AM

Never mind!

this is what I did:

var gridname = null;

gridname = sender._ID;

var gridObj = $find(gridname) //To get the Grid Object

 


Prabhu Sarvesan [Syncfusion]
Replied On December 16, 2013 01:32 AM

Hi Yulia,

Thanks for your interest in Syncfusion products.

The solution for your query “dynamically call the grid in the script” has been achieved using window object. To achieve this assign grid id in window object and access this window object wherever you needed in the script.

For your convenience we have shown the code snippets below,

Code Snippet:

function deleteConfirmation(sender, args)

    {

      window.gridId = sender.get_ID();    //store current grid Id in window object

      ...

    }

$("#confrim").click(function ()

     {

       var gridID = window.gridId;      //get current grid Id

       var gridObj = $find(gridID);     //find current grid object

       ...

      }

 

Please let us know if you need any further assistance.

Regards,

Prabhu Sarvesan


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.

;