setting OnServerEditRow in javascript/ajax

Hi,

     How to call the event OnServerEditRow in javascript/ajax? Something in following way..

$("#SF_Grid_Options").ejGrid({
dataSource: response.d, OnServerEditRow: "EditRow_Save"});

1 Reply

TS Thavasianand Sankaranarayanan Syncfusion Team October 19, 2017 08:37 AM UTC

Hi Sir, 

Thanks for contacting Syncfusion support. 

We have analyzed your query and in your given code example that you want to call OnServerEditRow in ejGrid control. By default, OnServerEditRow which is used in ASP.Net for calling the server editing action. But in your case you have used in JavaScript. This is not the recommended way to use OnServerEditRow

According to your query, we suspect that you want to bind the data in local and need to do CRUD operations in server side itself. So, we suggest you to enable remoteSaveAdaptor in ejGrid control to do CRUD operations in server side itself. 

Refer the below code example. 

[GridFeatures.aspx] 

<script type="text/javascript"> 
        var orderData = JSON.parse('<%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(this.gridDataSource)%>');  
         
        $("#Grid1").ejGrid({ 
             
            dataSource: ej.DataManager({ 
                json: orderData, // at initially local data binding 
 
                updateUrl: "Grid/Update", // for updating the editing values to db. 
                insertUrl: "Grid/Insert", 
                removeUrl: "Grid/Remove", 
                adaptor: new ej.remoteSaveAdaptor()//enable remoteSaveAdaptor 
            }), 
 
            --- 
 
           columns: [ 
                    { field: "OrderID", isPrimaryKey: true, headerText: "Order ID", textAlign: ej.TextAlign.Right, validationRules: { required: true, number: true }, width: 90 }, 
                     
               ---- 
           ] 
        }); 
         
    </script> 
 
--------------------------------------------------------- 
[GridFeatures.aspx.cs] 

                 public IEnumerable gridDataSource; 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            BindDataSource(); 
             
        } 
        private void BindDataSource() 
        { 
            int orderId = 10000; 
            int empId = 0; 
            for (int i = 1; i < 9; i++) 
            { 
                order.Add(new Orders(orderId + 1, "VINET", empId + 1, 32.38, new DateTime(2014, 12, 25), "Reims")); 
                 
                --- 
           } 
          
            this.gridDataSource = order; 
             
        } 

                 [WebMethod] 
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
        public static object Update(Orders value) 
        { 
            var record = order.Where(o => o.OrderID == value.OrderID).FirstOrDefault(); 
            if (record != null) 
            { 
                record.OrderID = value.OrderID; 
                record.CustomerID = value.CustomerID; 
                record.EmployeeID = value.EmployeeID; 
                record.Freight = value.Freight; 
                record.ShipCity = value.ShipCity; 
            } 
            return value; 
        } 
        [WebMethod] 
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
        public static object Insert(Orders value) 
        { 
            order.Insert(0,value); 
            return value; 
        } 
        [WebMethod] 
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
        public static void Remove(int key) 
        { 
            var record = order.Where(o => o.OrderID == key).FirstOrDefault(); 
            order.Remove(record); 
        } 


We have prepared a sample and it can be downloadable from the below location. 


Refer the help documentation. 


Regards, 
Thavasianand S. 


Loader.
Up arrow icon