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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

determine the id of the selected row

Thread ID:

Created:

Updated:

Platform:

Replies:

146351 Jul 31,2019 01:13 PM UTC Aug 5,2019 12:29 PM UTC jQuery 3
loading
Tags: ejmGrid
Ali Ossaily
Asked On July 31, 2019 01:13 PM UTC

Hello syncfusion support ,

Im trying to update and delete my record in grid using this code 

              $("#Grid").ejGrid({

                    dataSource: ej.DataManager({
                        json: e.result,
                        adaptor: new ej.remoteSaveAdaptor(),
                        insertUrl: "http://localhost:11055/api/user/PostUser",
                        updateUrl: "http://localhost:11055/api/user/UpdateUser/2",  
                        removeUrl: "http://localhost:11055/api/user/DeleteRole/2",
                    }),
              })
 my question is how to know the id of the selected record to update or delete, instead of typing it manually to send it to the api

thanks in advanced


Padmavathy Kamalanathan [Syncfusion]
Replied On August 1, 2019 01:59 PM UTC

Hi Ali, 

Thanks for contacting Syncfusion Support. 

QUERY: how to know the id of the selected record to update or delete, instead of typing it manually to send it to the api 
 
From your query we understand that you are trying to update and delete record using RemoteSaveAdaptor. For edit/delete/insert record, there is no need to manually send any id to the api.  

Please refer the below code snippet, 

In view 
 
<div id="Grid"> 
</div> 
    <script > 
 
        var gridData = @Html.Raw(Json.Encode(@ViewBag.dataSource)); 
        $(function () { 
            $("#Grid").ejGrid({ 
                dataSource: ej.DataManager({ 
                    json: gridData, 
                    insertUrl: "NormalInsert", 
                    updateUrl: "NormalUpdate", 
                    removeUrl: "NormalDelete", 
                    adaptor: "remoteSaveAdaptor", 
                }), 
                allowPaging: true, 
                editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true }, 
                toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.Add, ej.Grid.ToolBarItems.Edit, ej.Grid.ToolBarItems.Delete, ej.Grid.ToolBarItems.Update, ej.Grid.ToolBarItems.Cancel] }, 
                columns: [ 
                       { field: "OrderID", headerText: "Order ID", isPrimaryKey: true, width: 75, textAlign: ej.TextAlign.Right }, 
                        { field: "CustomerID", headerText: "Customer ID", width: 90 }, 
                ] 
            }); 
        }); 
    </script> 
In controller 

    public class GridController : Controller 
    { 
        public static List<OrderDetails> order = new List<OrderDetails>(); 
        public ActionResult GridFeatures() 
        { 
            if (order.Count() == 0) 
                BindDataSource(); 
            ViewBag.datasource = order; 
            return View(); 
        } 
        public ActionResult NormalUpdate(CRUDModel<OrderDetails> myObject) // method to update edited record 
        { 
            var ord = myObject.Value; 
            OrderDetails val = order.Where(or => or.OrderID == ord.OrderID).FirstOrDefault(); 
            val.OrderID = ord.OrderID; 
            val.CustomerID = ord.CustomerID; 
            return Json(myObject.Value); 
        } 
 
        public ActionResult NormalInsert(OrderDetails value) //method to insert new record 
        { 
            order.Insert(order.Count, value); 
            return Json(order); 
        } 
 
        public ActionResult NormalDelete(CRUDModel<OrderDetails> value) //method to delete record 
        { 
            order.Remove(order.Where(or => or.OrderID == int.Parse(value.Key.ToString())).FirstOrDefault()); 
            return Json(value); 
        } 
 
    } 

Please refer the below sample, 

Still facing the issue, please share us the below details, 
  1. Your controller and view page code
  2. Screenshot of error(if any)
  3. Explain us what do mean by id of record (primary key or index or something else?

If you have further queries, please get back to us. 

Regards, 
Padmavathy Kamalanathan 


Ali Ossaily
Replied On August 2, 2019 06:55 AM UTC

Dear Padmavathy Kamalanathan , 

thanks a lot , that's exactly what I'm looking for , it works .

Best Regards.

Padmavathy Kamalanathan [Syncfusion]
Replied On August 5, 2019 12:29 PM UTC

Hi Ali, 

We are happy to hear that your issue has been resolved. 

Feel free to get back to us if you need further assistance. 

Regards, 
Padmavathy Kamalanathan 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon