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.

Delete grid line using multiple primary key

Thread ID:

Created:

Updated:

Platform:

Replies:

123176 Feb 24,2016 02:32 AM Mar 7,2016 03:36 AM ASP.NET MVC 8
loading
Tags: Grid
Shanzida Sharaf
Asked On February 24, 2016 02:32 AM

Hi

I am trying to delete grid line where I have four primary key 

@(Html.EJ().Grid<emp.Models.UseDocLineModel>("FlatGrid")
                 .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.dataSource).UpdateURL("Update").InsertURL("NormalInsert").RemoveURL("DeleteLine").Adaptor(AdaptorType.RemoteSaveAdaptor))
            .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing();  })
         
            .ToolbarSettings(toolbar =>
            {
                toolbar.ShowToolbar().ToolbarItems(items =>
                {
                    items.AddTool(ToolBarItems.Add);
                    items.AddTool(ToolBarItems.Edit);
                    items.AddTool(ToolBarItems.Delete);
                    items.AddTool(ToolBarItems.Update);
                    items.AddTool(ToolBarItems.Cancel);
                });
            })
.Columns(col =>
                {
                    col.Field("org_id").HeaderText("Organization").IsPrimaryKey(true).TextAlign(TextAlign.Left).Width(70).Visible(false).Add();
                    col.Field("document_code").HeaderText("Document Code").IsPrimaryKey(true).TextAlign(TextAlign.Left).Visible(false).Width(70).Add();
                    col.Field("document_no").HeaderText("Document No").IsPrimaryKey(true).TextAlign(TextAlign.Left).Width(70).Visible(false).Add();
                    col.Field("line_no").HeaderText("line No").IsPrimaryKey(true).TextAlign(TextAlign.Left).Width(70).Visible(false).Add();
                     .............

In the controller , here is my code for DeleteLine

public ActionResult DeleteBudgetLine(int key, string key1, int key3, int key4)
        {
.................
         return Json(docLines, JsonRequestBehavior.AllowGet);
        }


Shanzida Sharaf
Replied On February 24, 2016 02:35 AM

sorry for incomplete thread

Hi

I am trying to delete grid line where I have four primary key 

@(Html.EJ().Grid<emp.Models.UseDocLineModel>("FlatGrid")
                 .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.dataSource).UpdateURL("Update").InsertURL("NormalInsert").RemoveURL("DeleteLine").Adaptor(AdaptorType.RemoteSaveAdaptor))
            .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing();  })
         
            .ToolbarSettings(toolbar =>
            {
                toolbar.ShowToolbar().ToolbarItems(items =>
                {
                    items.AddTool(ToolBarItems.Add);
                    items.AddTool(ToolBarItems.Edit);
                    items.AddTool(ToolBarItems.Delete);
                    items.AddTool(ToolBarItems.Update);
                    items.AddTool(ToolBarItems.Cancel);
                });
            })
.Columns(col =>
                {
                    col.Field("org_id").HeaderText("Organization").IsPrimaryKey(true).TextAlign(TextAlign.Left).Width(70).Visible(false).Add();
                    col.Field("document_code").HeaderText("Document Code").IsPrimaryKey(true).TextAlign(TextAlign.Left).Visible(false).Width(70).Add();
                    col.Field("document_no").HeaderText("Document No").IsPrimaryKey(true).TextAlign(TextAlign.Left).Width(70).Visible(false).Add();
                    col.Field("line_no").HeaderText("line No").IsPrimaryKey(true).TextAlign(TextAlign.Left).Width(70).Visible(false).Add();
                     .............

In the controller , here is my code for DeleteLine

public ActionResult DeleteBudgetLine(int key, string key1, int key3, int key4)
        {
.................
         return Json(docLines, JsonRequestBehavior.AllowGet);
        }

I am only getting  value for key not for the other. But I need to get all values to get the data. How can I get the primary key value for delete case

Gowthami V [Syncfusion]
Replied On February 25, 2016 06:17 AM

Hi Shanzida,

Thanks for using Syncfusion products.

We can achieve your requirement “get all primary key values to get the data” by passing the additional key values using the Headers of the ejDataManager. While performing delete action in the actionBegin event, add the required number of array of objects into Headers and retrieve them using the Request Object of the HttpRequestMessage. 

@(Html.EJ().Grid<emp.Models.UseDocLineModel>("FlatGrid")

                 .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.dataSource).UpdateURL("Update").InsertURL("NormalInsert").RemoveURL("DeleteLine").Adaptor(AdaptorType.RemoteSaveAdaptor))

    . . . .

    . . . .

    .ClientSideEvents(eve => { eve.ActionBegin("begin").ActionComplete("complete");})

    )

<script type="text/javascript">

        function begin(args) {

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

                args.model.dataSource.dataSource.headers = [];

                args.model.dataSource.dataSource.headers.push({ "additional_key": args.data.document_code, "additional_key1": args.data.document_no, "additional_key2": args.data.line_no });


            }

        }

        function complete(args) {

            if (args.requestType == 'delete')

                args.model.dataSource.dataSource.headers = [];//to avoid headers value to be interfered with other actions, emptied the Headers

        }
    </script>

//Perform delete

    public ActionResult DeleteLine(int key //primarykey value)

    {


    NORTHWNDEntities db = new NORTHWNDEntities();

    //getting additional key values

    string obj = Request.Headers.GetValues("additional_key")[0]; //key1

    int obj1 = Int32.Parse(Request.Headers.GetValues("additional_key1")[0]); //key2

    int obj2 = Int32.Parse(Request.Headers.GetValues("additional_key2")[0]); //key3

    . . . .

    . . . .

   //code for delete the record

    return Json(docLines, JsonRequestBehavior.AllowGet);
    }


We have already discussed about “how to pass custom headers to server through datamanager” in the below link,

https://www.syncfusion.com/kb/5963/how-to-send-custom-headers-to-server-using-datamanager
 
Regards,

Gowthami V.

Shanzida Sharaf
Replied On February 25, 2016 06:47 AM

Thanks for your quick reply. I will try and let you know my feedback.

Gowthami V [Syncfusion]
Replied On February 25, 2016 10:57 PM

Hi Shanzida,
 
Try the solution and get back to us if you need further assistance.
 
Regards,
 
Gowthami V.

Shanzida Sharaf
Replied On March 1, 2016 04:29 AM

Hi Gowthami,

I have tried this solution and it works for me. 

Just one more query for you. Could you please let me know in the delete method which key return e.g. Delete ( int key) Is this is the first primary key of my model? 

Thanks for your help.

kind regards,
Shanzida

Gowthami V [Syncfusion]
Replied On March 2, 2016 03:37 AM

Hi Shanzida,

No. The last primary key column value will be passed to the Delete controller method as a key parameter.

Refer to below screenshot (OrderID, EmployeeID and Freight fields are PrimaryKey field)

Grid



Delete method



Regards,

Gowthami V.

Mahindra Morar
Replied On March 4, 2016 01:20 AM

Hi, Is there an option to return a error message if the deletion fails on the server side?

Gowthami V [Syncfusion]
Replied On March 7, 2016 03:36 AM

Hi Shanzida,

We have already discussed about the topic “Displaying error message if server action failed” in the below KB document,
                                                                                                                                  
https://www.syncfusion.com/kb/5170/how-to-display-custom-error-message-on-ajax-action-failture

Regards,

Gowthami V.


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.

;