Kendo Grid C# - Select current page without refresh datasource again

Daniel Veintimilla Tenorio

i have been trying to fix this, what i want to do is:

I have a datasource who gets data from server, when i go to server, i get the list of items, then i have to search the item i have to select (This item could be in any page), after i have the item and the page where the item is located (assuming each page has 30 items), then i call LINQ expression to skip the required ammount of data and take 30. Finally i return this list to the client side.

When data arrives to client i need to "auto-select" the selected item and change the page to locate the user in the right page where the selected item is located. I have the new page, skip, selected value and everything in the client side again.

What do you suggest to me to change the page into the kendo grid datasource without call a new refresh and go to the server again?

This is how the datasource looks like:

return new kendo.data.DataSource({
        serverPaging: true,
        transport: {
            read: {
                url: URLController.Current().getURL('MyURL'),
                contentType: 'application/json',
                accepts: 'application/json',
                type: 'POST'
            },
            parameterMap: function(data, type) {
                if (data) {
                    return JSON.stringify(
                    {
                        data: jsonData,
                        pageSize: data.pageSize,
                        skip: data.skip,
                        take: data.take
                    });
                }
            }
        },
        schema: {
            data: function (data) {
                var dropDownData = JSON.parse(data);
                gridElement.attr('data-model', JSON.stringify({ data: data }));

                return dropDownData.Data;
            },
            total: function (data) {
                var dropDownData = JSON.parse(data);
                return dropDownData.total;
            },
            model: {
                id: 'ID'
            }
        },
        pageable: true,
        pageSize: 30,
        error: function(e) {
            alert('Error ' + e);
        }
    });

When the grid data is bounded i have to change the page to current page number and then select the current item.

grid.one('dataBound', function (e) {
            var currentGridElement = this.element;
            var currentModel = currentGridElement.attr('data-model');
            var currentJsonData = parseDropDownDataJSONString(currentModel).data;
            var gridDataSource = this.dataSource;
            var selection = gridDataSource.get(currentJsonData.selectedValue);
            if (selection != undefined) {
                var row = currentGridElement.find('tbody>tr[data-uid=' + selection.uid + ']');
                if (row != undefined) {
                    currentGridElement.attr('data-closeByChange', false);
                    gridDataSource.page(currentJsonData.pageNumber);
                    this.select(row);
                    dexonDropDownGrid.combobox().text(selection.DISPLAY);
                }
            }
            var aaaa = 0;
        });

This is how my databound event listener looks like, when i try to set the page it calls again the server and i got more delay to load the right data.

Is there any way to solve this?

Thanks

Harry Burns

Have the same problem.

There is how I fix that(not the best solution ever, but it works):

var forcedPageChange = false;
var cachedResult;

var dataSource = new kendo.data.DataSource({
    transport: {
        read: function (options) {
            if (forcedPageChange) { // prevent data request after manual page change
                forcedPageChange = false;
                options.success(cachedResult);
                cachedResult = null;
                return;
            }

            gridDataProvider.getData() // promise of data
                    .then(function (result) {
                        // check if current page number was changed
                        if ($scope.gridConfig.dataSource.page() !== result.pageNumber ||
                                $scope.gridConfig.dataSource.pageSize() !== result.rowsPerPage) {
                            cachedResult = _.clone(result);
                            forcedPageChange = true;
                            options.page = result.pageNumber;
                            options.pageSize = result.rowsPerPage;
                            $scope.gridConfig.dataSource.query(options);
                        }

                        options.success(result);
                    }, function () {
                        options.error();
                    });
        }
    },
    schema: {
        data: function (response) {
            return response.items;
        },
        total: function (response) {
            return response.totalCount;
        }
    },
    //...
    serverPaging: true,
    serverSorting: true,
    serverFiltering: true
});

I found that dataSource.page(newPageNumber) doesn't work in this situation. It just drop page number to 1.

This solution works, but I still have a bug with missing sorting icon after dataSource.query(options)...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Kendo Grid datasource refresh does not work in IE

From Dev

How do I refresh kendo grid when datasource is changed

From Dev

Kendo UI Grid: I lose pagination after datasource refresh

From Dev

Kendo UI Grid: I lose pagination after datasource refresh

From Dev

datasource not binding to kendo grid

From Dev

Kendo UI grid header disappears/shifts on page refresh

From Dev

Kendo Grid datasource never updating

From Dev

Binding Kendo grid to a Complex dataSource

From Dev

kendo grid date format datasource

From Dev

MultiColumn header with Datasource Kendo Grid

From Dev

Kendo Grid MVC - DataSource Error

From Dev

html refresh the page without sending form data again besides ajax

From Dev

Submit form without redirect to action page, but refresh current page

From Dev

How to refresh/reload kendo comboBox dataSource with AngularJs?

From Dev

How to refresh/reload kendo comboBox dataSource with AngularJs?

From Dev

kendo grid do not refresh on update

From Dev

Kendo grid refresh issue in mobile

From Dev

Kendo UI Grid, setting page to 1 without double postback

From Dev

In MVC 3, how do I refresh kendo grid in a partial view after I select a row in another partial view Kendo Grid?

From Dev

Exporting all data from Kendo Grid datasource

From Dev

How to know kendo grid dataSource change

From Dev

Unable to set Kendo UI Grid DataSource

From Dev

kendo Grid DataSource with OData format = json

From Dev

Get datasource of child grid in Kendo using angular

From Dev

Different Kendo grid Datasource when grouping applied

From Dev

How to use SignalR Datasource with Kendo Grid

From Dev

kendo Grid DataSource with OData format = json

From Dev

How to use SignalR Datasource with Kendo Grid

From Dev

Getting Kendo Grid from its DataSource

Related Related

  1. 1

    Kendo Grid datasource refresh does not work in IE

  2. 2

    How do I refresh kendo grid when datasource is changed

  3. 3

    Kendo UI Grid: I lose pagination after datasource refresh

  4. 4

    Kendo UI Grid: I lose pagination after datasource refresh

  5. 5

    datasource not binding to kendo grid

  6. 6

    Kendo UI grid header disappears/shifts on page refresh

  7. 7

    Kendo Grid datasource never updating

  8. 8

    Binding Kendo grid to a Complex dataSource

  9. 9

    kendo grid date format datasource

  10. 10

    MultiColumn header with Datasource Kendo Grid

  11. 11

    Kendo Grid MVC - DataSource Error

  12. 12

    html refresh the page without sending form data again besides ajax

  13. 13

    Submit form without redirect to action page, but refresh current page

  14. 14

    How to refresh/reload kendo comboBox dataSource with AngularJs?

  15. 15

    How to refresh/reload kendo comboBox dataSource with AngularJs?

  16. 16

    kendo grid do not refresh on update

  17. 17

    Kendo grid refresh issue in mobile

  18. 18

    Kendo UI Grid, setting page to 1 without double postback

  19. 19

    In MVC 3, how do I refresh kendo grid in a partial view after I select a row in another partial view Kendo Grid?

  20. 20

    Exporting all data from Kendo Grid datasource

  21. 21

    How to know kendo grid dataSource change

  22. 22

    Unable to set Kendo UI Grid DataSource

  23. 23

    kendo Grid DataSource with OData format = json

  24. 24

    Get datasource of child grid in Kendo using angular

  25. 25

    Different Kendo grid Datasource when grouping applied

  26. 26

    How to use SignalR Datasource with Kendo Grid

  27. 27

    kendo Grid DataSource with OData format = json

  28. 28

    How to use SignalR Datasource with Kendo Grid

  29. 29

    Getting Kendo Grid from its DataSource

HotTag

Archive