1

Hi have a JS function that is used to loop through the data of a multipage grid. This following function should loop 3 times, but it stops after the second loop. What am I doing wrong?

The following

function GetAnimalsUsingFilters() {
        var dataSource = $("#view-GenomicEvaluationInventory-grid").data("kendoGrid").dataSource;
        var totalPages = 3;
        var targetPage = 1;
        while (targetPage <= totalPages) {
            dataSource.query({ page: targetPage, pageSize: 20, filter: dataSource.filter() })
                .then(function() {
                    var view = dataSource.view();
                    var viewItemId = 0;
                    while (viewItemId < view.length) {
                        filteredAnimals.push(view[viewItemId]['AnimalId']);
                        viewItemId++;
                    }
                    //Callback when done
                    if (targetPage === totalPages) {
                        GeneratePDFReport(dataSource);
                    }
                });
            targetPage++;
        }
    }

Or better yet, if you are familiar with Kendo grid, is there another way to get the filtered(column filtered) results across multiple pages?

Mark
  • 4,773
  • 8
  • 53
  • 91
  • 1
    `targetPage` doesn't have the value you think it has as of the first callback from `query` (its value as of the **first** callback will be 4). The linked question's answers explain why not and what to do about it. – T.J. Crowder Jan 28 '17 at 18:23

0 Answers0