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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Grid UrlAdaptor datasource and update

Thread ID:

Created:

Updated:

Platform:

Replies:

141637 Dec 23,2018 07:59 AM UTC Dec 31,2018 12:32 PM UTC ASP.NET Core - EJ 2 6
loading
Tags: DataGrid
Bernard Jurlina
Asked On December 23, 2018 07:59 AM UTC

Is there some complete and full example of filling the grid with UrlAdaptor and linq to sql query with passing the parameter?
And, I want to perform CRUD actions on that grid.

Thank!
Bernard.

Pavithra Subramaniyam [Syncfusion]
Replied On December 24, 2018 08:58 AM UTC

Hi Bernard, 
 
Thanks for contacting Syncfusion support. 
 
We have analyzed your query and We suggest you to refer to the below documentations to bind data to Grid using UrlAdaptor. 
 
Documentations :  
 
As we could see that you are using ASP.NET Core application. We suggest you to refer to the below general documentation link on linq to sql, 
 
Please refer the below code example, 
 
[index.cshtml] 
 
    <ejs-grid id="Grid" toolbar="@(new List<string>() {"ExcelExport", "Add", "Update", "Cancel" })"> 
        <e-data-manager url="/Home/UrlDatasource/" updateUrl="/Home/Update/" insertUrl="/Home/Insert/" removeUrl="/Home/Delete/" adaptor="UrlAdaptor" crossdomain="true"></e-data-manager> 
        <e-grid-editsettings allowEditing="true" allowAdding="true"></e-grid-editsettings> 
        ... 
   </ejs-grid> 
 
[HomeController.cs] 
 
public class HomeController : Controller 
{ 
        private NORTHWNDContext _context; 
        public HomeController(NORTHWNDContext context) 
        { 
            _context = context; 
        } 
 
        public IActionResult UrlDataSource([FromBody]DataManagerRequest dm) 
        { 
            IEnumerable DataSource = _context.Orders.Take(100).ToList(); 
            var count = _context.Orders.AsQueryable().Count(); 
            DataOperations operation = new DataOperations(); 
            if (dm.Where != null && dm.Where.Count > 0) //Filtering 
            { 
                DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator); 
            } 
            if (dm.Skip != 0) 
            { 
                DataSource = operation.PerformSkip(DataSource, dm.Skip);   //Paging 
            } 
            if (dm.Take != 0) 
            { 
                DataSource = operation.PerformTake(DataSource, dm.Take); 
            } 
            return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource);  
        } 
        public ActionResult Insert([FromBody]EditParams value) 
        { 
            var datas = _context; 
           datas.Orders.Add(value.value); 
            datas.SaveChanges(); 
            return Json(value); 
        } 
        public ActionResult Update([FromBody]EditParams value) 
        { 
            var db = _context; 
            db.Entry(value.value).State = EntityState.Modified; 
            db.SaveChanges(); 
            return Json(value); 
        } 
        public ActionResult Delete([FromBody]EditParams value) 
        { 
            var db = _context; 
            Orders order = db.Orders.Where(c => c.OrderID == Convert.ToInt32(value.key)).FirstOrDefault(); 
            db.Orders.Remove(order); 
            db.SaveChanges(); 
            return Json(order); 
        } 
} 
 
 
 
Please get back to us if you need further assistance. 
 
Regards, 
Pavithra S. 


Bernard Jurlina
Replied On December 25, 2018 07:40 AM UTC

Hi Pavithra,

and thank you for the answer. Please, can you check my other post about UrlAdaptor?

https://www.syncfusion.com/forums/141644/empty-grid-with-urladaptor

Thanks!
Bernard.

Pavithra Subramaniyam [Syncfusion]
Replied On December 26, 2018 05:18 AM UTC

Hi Bernard, 
 
We have checked the forum #141644 and to render the Grid data, column’s field name and the data source field name should be same. Due to serialization problem, your datasource field name is changed to camel case(firmaId) and so there is a mismatch in the column’s field which is in pascal case(FirmaId). This is why you don’t have data in Grid.  
 
To overcome this serialization problem, we suggest you to use the below solution in the Startup.cs file. 
 
[startup.cs] 
public void ConfigureServices(IServiceCollection services) 
        { 
            // Add framework services. 
            services.AddMvc().AddJsonOptions(options => 
            { 
                options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver(); 
            }); 
        } 
 
 
Please get back to us if you need further assistance. 
 
Regards, 
Pavithra S. 


Bernard Jurlina
Replied On December 26, 2018 08:47 AM UTC

Hi Pavithra.

I tried your solution with startup.cs and now I have my grid with rendered data in it, and it is ok. But everytime when I try tu update one of the rows, the value is null, like this:


What type is the posted object on NormalUpdate if my GridDatasource is some linq to sql query?

I attached my complete solution and my database. Login is admin@mail.com / Lozinka1.1

Thanks!
Regards,
Bernard.


Attachment: FormWebCore_e8b5eff6.rar

Bernard Jurlina
Replied On December 26, 2018 08:48 AM UTC

This is the database.

Bernard.

Attachment: FormWebCore_fa10916.rar

Pavithra Subramaniyam [Syncfusion]
Replied On December 31, 2018 12:32 PM UTC

Hi Bernard, 
 
Thanks for contacting Syncfusion support. 
 
We have analyzed the screenshot and the codes you have shared with us. We could see that you have not handled CRUD model class. You need to define CRUDModel(as generic) like below code example. Please find the below code example and sample for your reference. 
 
 
        public ActionResult Update([FromBody]CRUDModel<OrdersDetails> value) 
        { 
            var ord = value.value; 
            ... 
            return Json(value.value); 
        } 
 
        public class CRUDModel<T> where T : class 
        { 
 
            public T value { get; set; } 
        } 
 
 
 
 
Please refer the screenshot below, 
 
 
 
Please get back to us if you need further assistance. 
 
Regards, 
Pavithra S. 


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

;