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

DataGrid Issues (color change and not refreshing)

I have a grid that has a calculated column inside of it and I can update one of the values, the other is fixed.

Calculation is Count / Time and time is fixed. This grid is saving via Batch.


When I make a change, I'm not seeing any highlighted cells indicating change. Also, I would expect the calculated column to adjust to the new value prior to having to save. 



When I press Update and confirm I want to save changes. My grid just appears unaffected but the save does occur. 



I have to refresh the page to get the new data, but it does save and eventually work.




Here's some code.

<ejs-grid id="GridOverview" allowFiltering="true" allowSorting="true"
                      toolbar="@(new List<string>() {"Update", "Cancel"})" rowHeight="38" enableHover="true" enableVirtualization="true" allowSelection="true">
                <e-data-manager json="@Model.JsonGridData" adaptor="RemoteSaveAdaptor" batchUrl="/Session/BatchUpdate" enableCaching="false"></e-data-manager>
                <e-grid-filtersettings type="Menu"></e-grid-filtersettings>
                <e-grid-editSettings allowEditing="true" mode="Batch"></e-grid-editSettings>
                <e-grid-selectionsettings persistSelection="true" type="Multiple" checkboxOnly="true"></e-grid-selectionsettings>
                <e-grid-columns>

                    <e-grid-column field="RateId" headerText="Id" isPrimaryKey="true" width="75" allowEditing="false" visible="false"></e-grid-column>
                    <e-grid-column field="Name" headerText="Measure" filter="@(new {type = "CheckBox"})" clipMode="EllipsisWithTooltip" width="75" allowEditing="false"></e-grid-column>
                    <e-grid-column field="Count" allowEditing="true" headerText="Count" width="75" allowFiltering="false" validationRules="@(new { required=true})"></e-grid-column>
                    <e-grid-column field="RatePerMinute" template="#coltemplate" headerText="Rate Per Minute" allowSorting="true" width="75" allowEditing="false" allowFiltering="false"></e-grid-column>
                    <e-grid-column field="ModifiedBy" headerText="ModifiedBy" filter="@(new {type = "CheckBox"})" clipMode="EllipsisWithTooltip" width="75" allowEditing="false" ></e-grid-column>
                    <e-grid-column field="ModifiedAt" headerText="ModifiedAt" filter="@(new {type = "CheckBox"})" clipMode="EllipsisWithTooltip" width="75" allowEditing="false"></e-grid-column>
                </e-grid-columns>
            </ejs-grid>


@Model code

   public List<SessionGridInfo> GridData { get; set; } = new List<SessionGridInfo>();

        private object[] _jsonGridData { get; set; }
        public object[] JsonGridData
        {
            get { return GridData.Select(s => (object) s).ToArray(); }
            set { _jsonGridData = value; }
        }

 public class SessionGridInfo
    {
        [Key] public int RateId { get; set; }
        public string Name { get; set; }
        public int Count { get; set; }
        public int Minutes { get; set; }
        public bool Edited { get; set; }
        public string ModifiedBy { get; set; }
        public DateTimeOffset? ModifiedAt { get; set; }
    }



@controller code
public IActionResult BatchUpdate([FromBody] CRUDModel batchmodel)
        {
            int id = 0;
            int returnValue = 0;
            if (batchmodel.Changed != null)
            {
                for (var i = 0; i < batchmodel.Changed.Count(); i++)
                {
                    var item = JsonConvert.DeserializeObject<SessionGridInfo>(batchmodel.Changed[i].ToString());
                    id = item.RateId;
                    returnValue = _MeasureRepository.UpdateRateData(item.RateId, item.Count, User.Identity.Name);
                }
            }

            //simply return to the same page, just force a refresh
            var rateData = _MeasureRepository.GetSessionRatesFromSingleRateId(id);

            var session = rateData.First().SessionId;

            //have tried a redirect to same page to load again and act like a refresh, but does not work.

            return Details(session);
            //also have tried to use a Redirect to fire refresh.
            //return RedirectToAction("Details", controllerName: "Session", routeValues: new {id = session});
        }


Here is code concerning the calculated column.


    <script id="coltemplate" type="text/template">

        <span>${format(data)}</span>

    </script>

    <script type="text/javascript">

        var format = function (value) {

            var count = value.Count;
            var minutes = @Html.Raw(@Model.Session.Minutes);

            return (count / minutes).toFixed(2);
        }

Any help to any issue listed here would be helpful. I'm fairly new to ASP.NET Core so it maybe misuse of concepts entirely.

Thanks.

3 Replies

PS Pavithra Subramaniyam Syncfusion Team August 2, 2019 08:42 AM UTC

Hi Mark, 
 
Thanks for contacting Syncfusion support. 
 
We have checked your code and we suggest you to return the “batchModel” value to the View to update the Grid So you don’t need to refresh the page again to see the changes.  
 
We have prepared a simple sample based on your requirement.  Please refer to the below code example, documentation link  and sample link for more information. 
 
[index.cshtml] 
 
<ejs-grid id="GridOverview" allowFiltering="true" allowSorting="true" 
          toolbar="@(new List<string>() {"Update", "Cancel"})" rowHeight="38" enableHover="true" allowSelection="true"> 
    <e-data-manager json="@ViewBag.data.ToArray()"  adaptor="RemoteSaveAdaptor" batchUrl="/Home/BatchUpdate"></e-data-manager> 
    <e-grid-filtersettings type="Menu"></e-grid-filtersettings> 
    <e-grid-editSettings allowEditing="true" mode="Batch"></e-grid-editSettings> 
    <e-grid-selectionsettings persistSelection="true" type="Multiple" checkboxOnly="true"></e-grid-selectionsettings> 
    <e-grid-columns> 
 
        <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" width="75" visible="false"></e-grid-column> 
        <e-grid-column field="Freight" allowEditing="true" headerText="Freight" width="75" allowFiltering="false" validationRules="@(new { required=true})"></e-grid-column> 
        <e-grid-column field="RatePerMinute" template="#coltemplate" headerText="Rate Per Minute" allowSorting="true" width="75" allowEditing="false" allowFiltering="false"></e-grid-column> 
 
    </e-grid-columns> 
</ejs-grid> 
 
<script id="coltemplate" type="text/template"> 
 
    <span>${format(data)}</span> 
 
</script> 
 
<script type="text/javascript"> 
 
        var format = function (value) { 
            var count = value.Freight; 
            var minutes =2; 
 
            return (count / minutes).toFixed(2); 
        } 
    </script> 
 
[controller.cs] 
public IActionResult BatchUpdate([FromBody]CRUDModel<OrdersDetails> batchmodel) 
        { 
            if (batchmodel.Changed != null) 
            { 
                for (var i = 0; i < batchmodel.Changed.Count(); i++) 
                { 
                    var ord = batchmodel.Changed[i]; 
                    OrdersDetails val = orddata.Where(or => or.OrderID == ord.OrderID).FirstOrDefault(); 
                    val.OrderID = ord.OrderID; 
                    val.EmployeeID = ord.EmployeeID; 
                    val.CustomerID = ord.CustomerID; 
                    val.Freight = ord.Freight; 
                } 
            } 
 
            if (batchmodel.Deleted != null) 
            { 
                for (var i = 0; i < batchmodel.Deleted.Count(); i++) 
                { 
                    orddata.Remove(orddata.Where(or => or.OrderID == batchmodel.Deleted[i].OrderID).FirstOrDefault()); 
                } 
            } 
 
            if (batchmodel.Added != null) 
            { 
                for (var i = 0; i < batchmodel.Added.Count(); i++) 
                { 
                    orddata.Insert(0, batchmodel.Added[i]); 
                } 
            } 
            var data = orddata.ToList(); 
            return Json(batchmodel); 
        } 
 
 
Please get back to us if you need any further assistance on this. 
 
Regards, 
Pavithra S. 



UN Unknown Syncfusion Team August 13, 2019 12:07 AM UTC

Thank you, this is what I needed.


BS Balaji Sekar Syncfusion Team August 13, 2019 06:16 AM UTC

Hi Mark, 
 
Thanks for your update, 
 
We glad to hear that your problem has been resolved. 
 
Please get back to us if you need further assistance. 
 
Regards, 
Balaji Sekar. 


Loader.
Live Chat Icon For mobile
Up arrow icon