Kendo Grid dataBond property is not setting the value

0 Answers 9 Views
Grid
Muhammad Tufail
Top achievements
Rank 1
Muhammad Tufail asked on 19 May 2024, 09:48 PM
The below code where I getting the list of data from List c# method and all the data is properly binding with all the columns property. But the problem is when I am passing a hrtotal and it is not setting dataBond property.
<div id="totalHours">
</div>

<script>
var griddataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: '@Url.Action("List", "GLID")',
                    dataType: "json",
                   success: function (result) {
                    var totalHours = result.totalhr;
                   }
                },
            schema: {
                data: "data",
                total: "total",
              }
});

griddataSource.read();
        $("#grid").kendoGrid({
            dataSource: griddataSource,
            toolbar: ["excel"], 
            dataBound: function(e) {
                    resizeGrid(e);
                    var totalHours =  e.totalhr; // ****** I want to update the value of totalHour
                    $("#totalHours").text("Total new Hours: " + totalHours);
            },
            columns: [
            ]
        });
</script>

The below code is JsonResult List() method where I am passing totalhr through json.
var totalHours = list.Sum(item => item.Hours);
return Json(new { total = total, totalhr = totalHours, data = data }, JsonRequestBehavior.AllowGet);
Neli
Telerik team
commented on 23 May 2024, 04:52 AM

Hi,

The dataBound event handler will not provide information about the entire server response. I would suggest utilizing the dataSource requestEnd event. Below is an example:

dataSource: {
                requestEnd: function (result) {                  
                    var totalHours = result.response.totalhr;
                    $("#totalHours").text("Total new Hours: " + totalHours);
                },
                transport: {
                    read: {
                    url: '@Url.Action("Orders_Read", "Grid")',
                    dataType: "json"
                    },
                },
                .......
            },

Regards,

Neli

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Muhammad Tufail
Top achievements
Rank 1
Share this question
or