e

I'm using ASP .NET Core and Syncfusion.EJ2. I added the dependency of Syncfusion.EJ2 with NuGet, I added @addTagHelper "*, Syncfusion.EJ2" in _ViewImports.cshtml, I added script manager , <script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js"></script>,  <link rel="stylesheet" rel='nofollow' href="https://cdn.syncfusion.com/ej2/fabric.css" />  in _layout.cshtml and I converted my grid to use Syncfusion 2 like this:

<ejs-grid id="detailsGrid" [email protected] allowpaging="true" allowsorting="true" allowfiltering="true" width="1800" allowtextwrap="true"

          allowgrouping="true" toolbar='@new List<string> { "Edit", "Update", "Cancel" }' >

    <e-datamanager id="FlatData" updateUrl="SalesFulfillmentFileContent/Update" adaptor="UrlAdaptor"></e-datamanager>

    <e-grid-pagesettings pagesize="20"></e-grid-pagesettings>

    <e-grid-editsettings allowediting="true"></e-grid-editsettings>

    <e-grid-groupsettings columns="@(new string[] {"OrderDate", "CustomerName"})"></e-grid-groupsettings>

    <e-grid-columns>

        <e-grid-column field="UploadDate" headertext="Upload Date" format="dMy" width="160" allowEditing="false"></e-grid-column>

        <e-grid-column field="OrderDate" headertext="Order Date" format="dMy" width="100" edittype="Datepicker"> </e-grid-column>

        <e-grid-column field="CustomerName" headertext="Customer Name" width="160"></e-grid-column>

        <e-grid-column field="ArticleCode" headertext="Article Code" width="100"></e-grid-column>

        <e-grid-column field="ArticleName" headertext="ArticleName" width="160"></e-grid-column>

        <e-grid-column field="TUQuantityOrdered" headertext="TU Quantity Ordered" width="160" edittype="NumericEdit"></e-grid-column>

        <e-grid-column field="TotalContent" headertext="Total Content" width="160" edittype="NumericEdit"></e-grid-column>       

        <e-grid-column field="RowKey" headertext="" visible="false" isprimarykey="true"></e-grid-column>

    </e-grid-columns>

</ejs-grid>

This is what I have on codebehind: the parameter "id" is sent from another page and  it has values in debuger, also ViewBag.DataSource receives values :

  public IActionResult SalesFulfillmentFileContent(string id)
        {
            if (!String.IsNullOrEmpty(id))
            {
                var salesFileContentLines = _salesContentFilesStorage.GetSalesFileContentLines(id);

                ViewBag.DataSource = salesFileContentLines;
            }
            return View();
        }

The grid isn't created, it looks like in the attached image:




14 Replies

AI Amalia Ipatiov February 23, 2018 11:10 AM UTC

I found that if I remove e-grid-editsettings and e-datamanagerthe grid show data in the grid. But I need the Update action in the grid . On controller I have the actions methods:

public IActionResult SalesFulfillmentFileContent(string id)
        {
             if (!String.IsNullOrEmpty(id))
            {
                var salesFileContentLines = _salesContentFilesStorage.GetSalesFileContentLines(id);
                ViewBag.datasource = salesFileContentLines;
            } 
            return View(); 
        }

       

        [HttpPut]
        public ActionResult Update(Syncfusion.EJ2.Grids.Grid detailsGrid, string id)
        {       
               .......
            return View();
        }


DR Dhivya Rajendran Syncfusion Team February 26, 2018 05:10 PM UTC

Hi Amalia, 
Thanks for using Syncfusion Products, 
 
We have analyzed your query, and we suspect that you have missed to mention the url  property in your sample so that data is not displayed in grid. By default, data are fetched from remote data and bound to the grid using url property of  DataManager and CRUD operations are performed by using URL mentioned in the updateUrl property. Kindly refer the below code snippet and documentation link for more information about URL Adaptor and updateUrl. 
<ejs-grid id="detailsGrid" [email protected] allowpaging="true" allowsorting="true" allowfiltering="true" width="1800" allowtextwrap="true" 
          allowgrouping="true" toolbar='@new List<string> { "Edit", "Update", "Cancel" }' > 
    <e-datamanager id="FlatData" updateUrl="SalesFulfillmentFileContent/Update" adaptor="UrlAdaptor"></e-datamanager>   
  <e-grid-columns> 
    . . . . . .  
 </e-grid-columns> 
</ejs-grid> 
 
<ejs-grid id="detailsGrid" datasource=ViewBag.DataSource allowpaging="true" allowsorting="true" allowfiltering="true" width="1800" allowtextwrap="true" 
          allowgrouping="true" toolbar='@new List<string> { "Edit", "Update", "Cancel" }' > 
    <e-datamanager id="FlatData" url="/Home/ SalesFulfillmentFileContent " updateUrl="/Home /Update" adaptor="UrlAdaptor"></e-datamanager> 
    <e-grid-columns> 
    . . . . . .  
 </e-grid-columns> 
</ejs-grid> 
 
Demo link:
URL Adaptor sample      : https://aspdotnetcore.syncfusion.com/Grid/UrlAdaptor#/material
 
 
Documentation Link:
URL Adaptor                     : http://ej2.syncfusion.com/16.1.24/aspnet/documentation/grid/edit.html?syntax=tag#url-adaptor
 
 
If we have misunderstood your query could you please share more details of your query or could you please share issue reproducible sample that will be helpful for us to provide a better solution as early as possible. 
 
Regards,
R.Dhivya
 



AI Amalia Ipatiov February 27, 2018 09:04 AM UTC

Hello,

Thanks for the reply, but it's the same behaivor even if I added  the URL property as you have recommended:

   

where Sales is the directory. In the Controller , this is the UrlDatasource method:

 public IActionResult UrlDatasource([FromBody]Data dm, string id)
        {
            //var id = HttpContext.Request.Query["id"].ToString();
            IList salesFileContentLines = null;


            TempData["ID"] = id;
            ViewBag.ParamID = id;

            if (TempData["BlobName"] != null)
            {
                salesFileContentLines = _salesContentFilesStorage.GetSalesFileContentLines(TempData["BlobName"].ToString());
            }
            else if (!String.IsNullOrEmpty(id))
            {
                salesFileContentLines = _salesContentFilesStorage.GetSalesFileContentLines(id);
            }

            if (salesFileContentLines != null)
            {
                int count = salesFileContentLines.Count;
                var returnResult = dm.requiresCounts ? Json(new { result = salesFileContentLines.Skip(dm.skip).Take(dm.take).ToList(), count = count }) : Json(salesFileContentLines);

                return returnResult;
            }
            else
            {
                return null;
            }
        }

public class Data
        {

            public bool requiresCounts { get; set; }
            public int skip { get; set; }
            public int take { get; set; }
        }


AI Amalia Ipatiov February 27, 2018 01:42 PM UTC

I created a blank project using Syncfusion 2 with the grid and controller that will manage the grid. 
 - In the layout page I added the script manager and the reference to the syncfusion scripts:  <script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js"></script>;
-  in _ViewImports I added @addTagHelper "*, Syncfusion.EJ2", and the packages were included with NuGet.

I attached the project. Can you please review it and tell me what it's wrong? 



Attachment: Syncfusion2Demo_deea0a62.zip


DR Dhivya Rajendran Syncfusion Team February 28, 2018 10:59 AM UTC

Hi Amalia, 
We have analyzed and validated your sample. In the above sample shows 404 error because the url path is not referred the controller UrlDatasource method so that the data is not rendered in Grid. Here I have mentioned the code snippet and modified sample link. 
<ejs-grid  id="detailsGrid" allowpaging="true" allowsorting="true" width="1000" allowtextwrap="true" 
              allowgrouping="true" toolbar='@new List<string> { "Edit", "Update", "Cancel" }'> 
        <e-datamanager id ="1" url="/Index/UrlDatasource" adaptor="UrlAdaptor" updateUrl="/Index/Update"></e-datamanager> 
        . . . . .  
        <e-grid-editsettings allowediting="true" mode="Normal"></e-grid-editsettings> 
        <e-grid-columns> 
        . . . . . 
        </e-grid-column> 
        </e-grid-columns>
        </ ejs-grid >
 
 

Regards,
R.Dhivya 



AI Amalia Ipatiov February 28, 2018 12:56 PM UTC

 Thanks for the review. My problem is partial resolved. Now my demo app that you review it is working, but if I return to my real project and I add the following data manager the rows from grid isn't ok rendered. In the debuger I checked and I have the rows in the Json Result but the rows from the grid are displayed empty. I don't have any other css styles.

 <e-datamanager url="/Sales/[email protected]" adaptor="UrlAdaptor" updateUrl="/Sales/Update"></e-datamanager>




AI Amalia Ipatiov February 28, 2018 04:35 PM UTC

I solved the second issue with empty rows from the grid. Now the rows are displayed fine but this ssecond issue was generated by the columns field names that in my page , they started with uppercase letter, such as CustomerName, ArticleCode, like I saw in the documentation. After I changed the column names to start with lowercase letters(JSON format) the issue was solved.

This means that your documentation is confusing because on all the resources , the fields names appears with uppercase letters, which is wrong! 

https://ej2.syncfusion.com/16.1.24/aspnet/documentation/grid/how-to.html?syntax=tag#display-custom-tooltip-for-columns-in-grid






DR Dhivya Rajendran Syncfusion Team March 1, 2018 11:28 AM UTC

Hi Amalia , 
Sorry for the inconvenience caused.

We have analyzed your problem this is because of the JSON serialize setting no longer default to the DefaultContractResolver instead  it defaults to the CamelCasePropertyNamesContractResolver. You can use the following code in your Startup.cs file to resolve your problem and we have provide a sample for your reference. 
  public void ConfigureServices(IServiceCollection services) 
        { 
            services.AddMvc(). 
            AddJsonOptions(options => 
                { 
                    // JSON serialization not defaulting to default? 
                    options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver()
                }); 
        } 


Regards,
R.Dhivya 



AI Amalia Ipatiov March 1, 2018 01:35 PM UTC

Thanks, yes this solution  solved my issue  and now in the grid I added the column with uppercase letters. 
Please update the documentation, I spent 1 week to solve these issues.


DR Dhivya Rajendran Syncfusion Team March 2, 2018 08:52 AM UTC

Hi Amalia,

Sorry for the inconvenience caused , 
we will update the documentation which is in live. 
Regards,
R.Dhivya 



MM Mihai Moisei replied to Dhivya Rajendran March 12, 2018 12:20 AM UTC

Hi Amalia,

Sorry for the inconvenience caused , 
we will update the documentation which is in live. 
Regards,
R.Dhivya 


How can  localize  this grid ?


IR Isuriya Rajan Syncfusion Team March 12, 2018 12:30 PM UTC

Hi Amalia, 
 
We can apply the localization using the locale property. 

Please refer the below code example  

<script> 
    ej.base.L10n.load({ 
        "es-AR": { 
            "grid": { 
                "GroupDropArea": "Arrastra un encabezado de columna aquí para agrupar su columna", 
                "Add": "agregar", 
                "Edit": "editar", 
                "Cancel": "cancelar", 
                "Update": "actualizar", 
                "Delete": "Borrar" 
            }, 
            "pager": { 
                "currentPageInfo": "{0} de {1} páginas", 
                "totalItemsInfo": "({0} artículos)", 
                "firstPageTooltip": "Ir a la primera página", 
                "lastPageTooltip": "Ir a la última página", 
                "nextPageTooltip": "Ir a la página siguiente", 
                "previousPageTooltip": "Regresar a la pagina anterior", 
                "nextPagerTooltip": "Ir al siguiente buscapersonas", 
                "previousPagerTooltip": "Ir al buscapersonas anterior", 
                "pagerDropDown": "Artículos por página" 
            } 
        } 
    }); 
</script> 
 
<ejs-grid id="detailsGrid" allowpaging="true" allowsorting="true" width="1000" allowtextwrap="true" 
              allowgrouping="true" locale="es-AR" toolbar='@new List<string> { "Edit", "Update", "Cancel" }'> 
        <e-grid-columns> 
 
            <e-grid-column field="CustomerName" headertext="Customer Name" width="160"></e-grid-column> 
    </e-grid-columns> 
</ejs-grid> 

Refer the sample for your reference: 


We will include this in our documentation link and will release in any one of the release. 

Regards 
Isuriya R 



MM Mihai Moisei March 13, 2018 06:37 AM UTC

Thanks very much. 
Can extend this sample with a CRUD on mssql  database ?



MF Mohammed Farook J Syncfusion Team March 14, 2018 05:06 PM UTC

Hi Amalia, 
 
Based on your request , we have created a sample with ‘CRUD’ operation with “UrlAdaptor” Grid. Please find the code example. 
 
 
[index.cshtml] 
 
<script> 
 
    ej.base.L10n.load({ 
        "es-AR": { 
            "grid": { 
. . . 
            } 
        } 
    }); 
</script> 
 
 
<ejs-grid id="Grid" allowPaging="true" allowsorting="true" width="1000" allowtextwrap="true"  
              allowgrouping="true" locale="es-AR" toolbar="@( new List<object>() {"Add","Edit","Delete","Update","Cancel"})"> 
    <e-grid-editsettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editsettings> 
    <e-datamanager url="/Home/UrlDatasource" insertUrl="/Home/Insert" updateUrl="/Home/Update" removeUrl="/Home/Remove" adaptor="UrlAdaptor"></e-datamanager> 
    <e-grid-pageSettings pageCount="2" pageSize="5"></e-grid-pageSettings> 
    <e-grid-columns> 
        <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="120"></e-grid-column> 
        <e-grid-column field="CustomerID" headerText="Customer ID" width="150"></e-grid-column> 
        <e-grid-column field="EmployeeID" headerText="Employee ID" textAlign="Right" width="120"></e-grid-column> 
        <e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" width="140"></e-grid-column> 
        <e-grid-column field="ShipCity" headerText="Ship City" width="150"></e-grid-column> 
    </e-grid-columns> 
</ejs-grid> 
 
 
 
[controller] 
 
    public class HomeController : Controller 
    { 
        public IActionResult Index() 
        { 
            return View(); 
        } 
        public IActionResult UrlDatasource([FromBody]Data dm) 
        { 
            var order = OrdersDetails.GetAllRecords(); 
            var Data = order.ToList(); 
            int count = order.Count(); 
            return dm.requiresCounts ? Json(new { result = Data.Skip(dm.skip).Take(dm.take), count = count }) : Json(Data); 
        } 
 
        public ActionResult Update([FromBody]CRUDModel<OrdersDetails> value) 
        { 
            var ord = value.value; 
            OrdersDetails val = OrdersDetails.GetAllRecords().Where(or => or.OrderID == ord.OrderID).FirstOrDefault(); 
            val.OrderID = ord.OrderID; 
            val.EmployeeID = ord.EmployeeID; 
            val.CustomerID = ord.CustomerID; 
            val.Freight = ord.Freight; 
            val.OrderDate = ord.OrderDate; 
            val.ShipCity = ord.ShipCity; 
 
            return Json(value.value); 
        } 
        //insert the record 
        public ActionResult Insert([FromBody]CRUDModel<OrdersDetails> value) 
        { 
 
            OrdersDetails.GetAllRecords().Insert(0, value.value); 
            return Json(value.value); 
        } 
        //Delete the record 
        public ActionResult CellEditDelete([FromBody]CRUDModel<OrdersDetails> value) 
        { 
            OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().Where(or => or.OrderID == int.Parse(value.key.ToString())).FirstOrDefault()); 
            return Json(value); 
        } 
  
 
Please find the sample for your reference 
 
 
Regards, 
J.Mohammed Farook 
 


Loader.
Up arrow icon