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

How to load nested function on read?

1 Answer 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Devineni
Top achievements
Rank 1
Devineni asked on 28 Sep 2015, 03:19 PM
I'm a scenario, where I should load the multiple methods to get the response for the grid. From the below code, I suppose to load the loadData() function in the read function. Code is showing below.

 

The loadData function is having nested function. Once the first method is completed I have to call the second method on promise of first method. Once all the method executed.  I've to call the parse function. ​ 

 

If I use single restApi It's working fine. But here I have ​methods method on promise... ​So how to handle this kind of scenario. 

 

dataSource: new kendo.data.DataSource({
     transport: {
        read: loadData
     },
     schema: {
        parse: $scope.kendoParse
         ......
         .......

 

 

function loadData(){
    atFacade.eventDataApi.getCurrentShift().then((data) => {
                $scope.fleetListingFilter.currentShift = data;
                getAllOperatingSummary();
            });
}
 
function getAllOperatingSummary() {
    var startDate = new Date().now() + " " + $scope.fleetListingFilter.currentShift.startTime;
    var endDate = new Date().now() + " " + $scope.fleetListingFilter.currentShift.endTime;
    var operatingSummary = new at.Models.OperatingSummaryReportFilter(events.PAYLOAD, [], startDate, endDate);
    $scope.fleetListingPromise = atFacade.eventDataApi.getOperatingSummaryReportData(operatingSummary).then((data) =>       {$scope.allVehicles = data;
                    loadAllVehicles();
                });
    }
 
     function loadAllVehicles() {
                $scope.fleetListingPromise = atFacade.eventDataApi.getAllVehicles().then((data: Array<any>) => {
                    for (var i = 0, total = data.length; i < total; i++) {
                        for (var j = 0, tot = $scope.allVehicles.length; j < tot; j++) {
                            if (data[i].id === $scope.allVehicles[j].vehicleId) {
                                data[i].summary = $scope.allVehicles[j];
                            }
                        }
                    }
                    $scope.vehicles = data;
                    $scope.kendoParse(data);
                });
            }
 
$scope.kendoParse = (result) => {
                var data = [];
                var results = atFacade.restangularService.stripRestangular(result);
                for (var i = 0; i < results.length; i++) {
                    var fleetListingData = {
                        name: results[i].name,
                        registrationNumber: results[i].registrationNumber,
                        operator: results[i].summary.operator,
                        lastStop: results[i].summary.lastStop
                    };
                    data.push(fleetListingData);
                }
                return { "results": data, "totalResults": data.length };
            };

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 30 Sep 2015, 02:22 PM

Hello Devineni,

 

It doesn't matter how many function you call all you have to do when the last function call occurs is to set the data trough options.success method. 

 

Here is a illustration - http://dojo.telerik.com/@rusev/aLoxo

 

Regards,
Nikolay Rusev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Devineni
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or