This is a migrated thread and some comments may be shown as answers.

Issue on updating kendo child grid locally

1 Answer 153 Views
Hierarchical Data Source
This is a migrated thread and some comments may be shown as answers.
Rowell
Top achievements
Rank 1
Rowell asked on 19 Aug 2014, 04:24 PM
Hi Guys,

I need you help on the problem that I'm encountering right now. I'm using Kendo I grid with Hierarchy and I have two date picker and button which is not part of the Grid (Please refer to the attachment grid.png). What I want to do is, when the "Update Date" button is clicked, the Period Start and Period End dates will be updated by what ever is selected in the datepicker outside the grid. All the data of all the child is more than 1,000 records. My current code is working, I was able to update all the data of all the child grid. The only problem is, the internet browser is not respoding due to a long running script. I expecting this process to be quick since I'm just only updating the data locally. Do you know a work around for this? Please see my code implementation below.

Grid initialization:

01.var grid = $("#gridJobsH");
02. 
03.grid.kendoGrid({
04.    dataSource: dataSource
05.    , columns: [               
06.        { field: 'HasSAPAccrualsTop', title: " ", template: '<span class="AccrualStatus-#= HasSAPAccrualsTop #"></span>', width: 50, filterable:false, sortable: false}            
07.        ,{ field: 'CommitmentCode', title: 'Purchase Order'}
08.        ,{ field: 'CommitmentSeller', title: 'Subcontractor'}                  
09.    ]
10.    , sortable: true
11.    , reorderable: true
12.    , groupable: false
13.    , filterable: true
14.    , columnMenu: true
15.    , selectable: false
16.    , pageable: false
17.    , resizable: true
18.    , scrollable: {
19.        virtual: true
20.    }
21.    , detailInit: detailInit
22.    , toolbar: [
23.        { template: kendo.template($("#gridJobsHToolbarTemplate").html()) }
24.     ]
25.});

Detail Grid:

01.//Detail grid
02.function detailInit(e) {
03.    $('<div class="hdChildGrid"></div>').appendTo(e.detailCell).kendoGrid({
04.        dataSource: {
05.            data: gridDetails
06.            , autoSync: false
07.            , schema: {
08.                model: {
09.                    id: "PhaseCode"
10.                    ,fields: {                             
11.                        HasSAPAccruals:{ editable: false }
12.                        ,PhaseCode: { editable: false }
13.                        ,Description: { editable: false }
14.                        ,PeriodStart: { editable: true, type: "date" }
15.                        ,PeriodEnd: { editable: true, type: "date" }
16.                        ,CommittedCost: { editable: false }
17.                        ,TotalCostActual: { editable: false }
18.                        ,Accruals: { editable: false }
19.                        ,Incurred: { editable: false, type: "number"  }
20.                        ,CurrentSAPValue: { type: "number" }
21.                        ,SAPAccrualValue: { type: "number"  }
22.                    }
23.                }
24.            }
25.            , filter: { field: "CommitmentCode", operator: "eq", value: e.data.CommitmentCode }
26.        }
27.        , columns: [   
28.            { field: 'HasSAPAccruals', title: " ", template: '<span class="AccrualStatus-#= HasSAPAccruals #"></span>', width: 50, filterable:false, sortable: false, locked: true, lockable: false}
29.            ,{ field: "PhaseCode", title: "Phase Code",  width: 150, locked: true, lockable: false }
30.            ,{ field: "Description", title: "Description", width: 150 }
31.            ,{ field: "PeriodStart", title: "Period Start", width: 150, format:"{0:MM-dd-yyyy}"}
32.            ,{ field: "PeriodEnd", title: "Period End", width: 150, format:"{0:MM-dd-yyyy}"}
33.            ,{ field: "CommittedCost", title: "PO Value", width: 110, type: "number", format: "{0:c}" }
34.            ,{ field: "TotalCostActual", title: "Expenditures", width: 130, type: "number" , format: "{0:c}"}
35.            ,{ field: "Accruals", title: "Accruals", width: 100, type: "number" , format: "{0:c}" }
36.            ,{ field: "Incurred", title: "Incurred", width: 100, format: "{0:c}" }
37.            ,{ field: "CurrentSAPValue", title: "Current SAP Value", width: 170, format: "{0:c}"}
38.            ,{
39.                field: "SAPAccrualValue"
40.                ,title: "SAP Accrual Value"
41.                ,width: 170
42.                ,format: "{0:c}"
43.                ,lockable: false
44.                ,editor: function(cont, options) {
45.                    var amt;
46.                     
47.                    kendo.culture("en-US");
48.                    amt = kendo.toString(options.model.CurrentSAPValue, "c");
49.                     
50.                    $("<span>" + amt + "</span>").appendTo(cont);
51.                }
52.            }
53.        ]
54.        , scrollable: true
55.        , sortable: true
56.        , filterable: true
57.        , columnMenu: true 
58.        , editable: true
59.        , resizable: true
60.        , selectable: "multiple"
61.        , save: function(d) {
62.            if (d.values.CurrentSAPValue) {
63.                d.model.set("SAPAccrualValue", d.model.Incurred - d.values.CurrentSAPValue);
64.                d.model.set('Dirty',true);
65.            }          
66.        }
67.    });
68.}

Button event:

01.var btnUpdateDate = $('#btnUpdateAllDate')
02.    ,infoDialog = $('#infoDialog')
03.    ,btnInfoOK = $("#btnInfoOK").data("kendoButton")
04.    ,infoDialogMsg = $('#infoDialogMsg');  
05.     
06.start = $("#StartDate").kendoDatePicker({value: new Date()}).data("kendoDatePicker");
07. 
08.end = $("#EndDate").kendoDatePicker({value: new Date()}).data("kendoDatePicker");
09. 
10.btnUpdateDate.kendoButton({
11.    click: function(e) {
12.        var startDate = start.value()
13.            ,endDate = end.value()
14.            ,parentGrid = $('#gridJobsH').data("kendoGrid")
15.            ,child = $('.k-detail-row').find('td.k-detail-cell').find('div.k-grid').data("kendoGrid");             
16.             
17.        if(endDate < startDate ) {
18.            infoDialogMsg.html('End date must be ahead to Start date.');
19.            infoDialog.data("kendoWindow").open();
20.        } else {
21.         
22.            var chilEl = $('.hdChildGrid')
23.                ,childGrid = $(chilEl[0]).data('kendoGrid');                   
24.                 
25.            if(childGrid != null) {
26.                var dataSource = childGrid.dataSource;
27.                 
28.                dataSource.fetch(function() {
29.                    var models = dataSource.data()
30.                      ,modelsLength = models.length;
31. 
32.                    for (var i = 0; i < modelsLength; i++) {
33.                        var m = models[i];
34. 
35.                        m.set('PeriodStart', startDate);
36.                        m.set('PeriodEnd', endDate);
37.                    }                   
38.                });
39.            }
40.        }      
41.    }
42.});

Your idea is highly appreciated.

Thanks

1 Answer, 1 is accepted

Sort by
0
Accepted
Alexander Valchev
Telerik team
answered on 21 Aug 2014, 08:43 AM
Hi Rowell,

The problem is connected with the following code:
m.set('PeriodStart', startDate);
m.set('PeriodEnd', endDate);

Generally speaking using the set method is the correct approach, however at that certain case it is better to work with the standard "=" operator. The set method forces Grid to refresh which means that in your case the Grid widget will refresh more than 1,000 times which is the reason for the poor performance.

Please try the following:

m.PeriodStart = startDate;
m.PeriodEnd = endDate;
m.dirty = true;
 
//after the loop finishes you should refresh the Grid
childGrid.refresh();

I hope this information will help.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Hierarchical Data Source
Asked by
Rowell
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or