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. Image for the cookie policy date
close icon

Save changes in Datatable

Hi Syncfusion!!

I working with Grid (DataTable as Datasource) and i need to perform Editing and then save it into the same Datatable,


My Grid :

@model System.Data.DataTable

@(Html.EJ().Grid<Object>("FlatGrid")

                    .Datasource((System.Data.DataTable)Model)

                    .AllowPaging()

                    .AllowSelection()

                    .AllowResizeToFit(true)

                    .AllowScrolling()

                    .EditSettings(edit => { edit.AllowEditing().EditMode(EditMode.Normal); })

                    .ToolbarSettings(toolbar =>

                    {

                        toolbar.ShowToolbar().ToolbarItems(items =>

                        {

                            items.AddTool(ToolBarItems.Edit);

                            items.AddTool(ToolBarItems.Update);

                            items.AddTool(ToolBarItems.Cancel);

                        });

                    })

                    .Columns(col =>

                    {


                        col.Field("ID").AllowEditing(false).Width(50).IsFrozen(true).IsPrimaryKey(true).Add();

                        col.Field("VAR1").AllowEditing(false).Width(200).Add();

                        col.Field("VAR2").AllowEditing(false).Width(100).IsFrozen(true).Add();

                        col.Field("VAR3").AllowEditing(false).Width(50).Add();

                        col.Field("VAR4").AllowEditing(false).Add();

                        col.Field("VAR5").AllowEditing(false).Add();

                        col.Field("VAR6").AllowEditing(true).EditType(EditingType.String).Add();


                    })


)


How can i change this to work??

Thanks

O.A


1 Reply

TS Thavasianand Sankaranarayanan Syncfusion Team August 29, 2017 02:42 PM UTC

Hi Aljane, 

Thanks for contacting Syncfusion support. 

We have analyzed your query and we suggest you to perform the CRUD operations in server side by specifying the adaptor type as RemoteSaveAdaptor adaptor and also specify the CRUD actions Url to the corresponding DataManager properties of grid. The corresponding server side CRUD actions methods has been triggered when we perform any CRUD action in grid.  

Refer the below screen shot. 

  1. Initial Rendering.

 

  1. While Editing.
 
 

  1. Edited value get in server side.

 


Refer the below code example. 

[Index.cshtml] 

@(Html.EJ().Grid<object>("Editing") 
        .Datasource(ds => ds.Json((System.Data.DataTable)ViewBag.dataSource) 
            .UpdateURL("ExternalUpdate").InsertURL("ExternalInsert").RemoveURL("ExternalDelete") 
            .Adaptor(AdaptorType.RemoteSaveAdaptor)) 
         
         
         .AllowPaging() 
         
         ---- 
 
       .Columns(col => 
        { 
            col.Field("OrderID").HeaderText("Order ID").IsIdentity(true).IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(90).ValidationRules(v => v.AddRule("required", true).AddRule("number", true)).Add(); 
             
            ----- 
 
       }) 
        
) 
 
 
------------------------------------- 
[HomeController.cs] 

 
        public ActionResult ExternalUpdate(EditableOrder value) 
        { 
           //do your stuff here for update a record in database 
        } 
 
        public ActionResult ExternalInsert(EditableOrder value) 
        { 
             
           //do your stuff here for remove a record in database 
 
       } 
 
        public void ExternalDelete(int key) 
        {   
 
            //do your stuff here for remove a record in database 
 
        } 
     } 


Refer the help documentation. 


Regards, 
Thavasianand S. 


Loader.
Live Chat Icon For mobile
Up arrow icon