This is a migrated thread and some comments may be shown as answers.
DataSource Read called twice
3 Answers 161 Views
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 02 Dec 2012, 12:11 AM
I am presenting the user with a text box in which they can enter a search term. When the search term changes I call the following script.
function fillGrid() {
    var grid = $("#Grid").data("kendoGrid");
    $("#ActionError").html("");
    grid.dataSource.page(1);
    grid.dataSource.read();
}
Let's say the original search term causes 10 pages to be displayed and that we are viewing page 10. So we are viewing, 190 of 200. And let's say the new search term only produces 100 items, what happens is that the grid is empty and the bottom line indicates we are viewing 190 of 100. Refreshing the grid corrects the problem, but I added the line "grid.dataSource.page(1);" above to do this automatically. But I have observed that this has the side effect of calling the Controller twice. Generally, I used grid.dataSource.read() to refresh the grid. So I am wondering what is the correct way to perform this operation so that I don't make two calls to the database. I guess that every time the grid is changed it updates. Is there a way to turn updating off, make changes to the grid, and then refresh it. 

3 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 03 Dec 2012, 08:12 AM
Hello Martin,

I suspect that what you need is to call DataSource.query method and provide the parameters. For example to page on first page with page size 10 and filter expression you will need the following expression:

<DataSource instance>.query({
 page: 1,
 pageSize: 10,
 filter: { operator: ">", field: "OrderID", value: 10248 }
})


Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Linda
Top achievements
Rank 1
answered on 23 Aug 2017, 09:46 PM

Hi

I have the same problem and try with <DataSource instance>.query .... but doesn't work

This is my code:

 // Restore the selected grid page.
                var pageToSelect = 0;
                gridSource.one('change', function (e) {
                    var currentPage = gridSource.page() || 1,
                        totalPages = gridSource.totalPages();

                    //gridSource.page(currentPage < totalPages ? currentPage : totalPages);
                    pageToSelect = currentPage < totalPages ? currentPage : totalPages;
             
                });

                gridSource.query({
                    page: pageToSelect,
                    pageSize: 10,
                });
                gridSource.read(); // READ

0
Preslav
Telerik team
answered on 25 Aug 2017, 11:34 AM
Hi Linda,

I believe that this behavior is caused by the read method of the dataSource. Remove the last line of the provided code and only a single read will be called.

If this is not the case, in order to continue my investigation, please send as an isolated Dojo that clearly replicates the issue. I will use it to fully understand the scenario and provide assistance to the best of my knowledge.

Regards,
Preslav
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Martin
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Linda
Top achievements
Rank 1
Preslav
Telerik team
Share this question
or