最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ReloadRefresh Kendo Grid - Stack Overflow

programmeradmin1浏览0评论

I need to reload all the grid (not only the data).

I'm trying with:

$('#GridName').data('kendoGrid').dataSource.read();
$('#GridName').data('kendoGrid').refresh();

but read() reloads only the data and refresh() is not working. When a user clicks on the button, I need to recreate all the table with new columns (I don't know how many columns or what columns, the server process it).

Users can change the columns that they see with a html checkbox. The first time the table charges correctly but if the user change the checkbox value the columns don't change. If deselect an option the column is empty and if the user adds an option, the new column don't appear.

How can I achieve this?

I need to reload all the grid (not only the data).

I'm trying with:

$('#GridName').data('kendoGrid').dataSource.read();
$('#GridName').data('kendoGrid').refresh();

but read() reloads only the data and refresh() is not working. When a user clicks on the button, I need to recreate all the table with new columns (I don't know how many columns or what columns, the server process it).

Users can change the columns that they see with a html checkbox. The first time the table charges correctly but if the user change the checkbox value the columns don't change. If deselect an option the column is empty and if the user adds an option, the new column don't appear.

How can I achieve this?

Share Improve this question edited Oct 11, 2018 at 17:04 Bruno de Andrade 1232 silver badges7 bronze badges asked Mar 13, 2018 at 16:30 RabegiRabegi 1231 silver badge7 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

You should destroy and recreate the grid to change the columns.

$.ajax(
{
    type: 'GET',
    url: yourURL,
    dataType: 'json',
    success: function (result) {
        $('#Grid').data('kendoGrid').destroy();
        $('#Grid').empty(); //necessary to remove the old html

        $("#grid").kendoGrid({
            dataSource: {
                data: result,
                schema: {
                    data: "d"
                }
            }
        });
    }
});

The result of your ajax should be something like:

var result = { 'd': [
    { description: "Description 1", number: 30, price: 3.5 },
    { description: "Description 2", number: 33, price: 4 },
    { description: "Description 3", number: 40, price: 4.5 }
]}

Do you want to attempt to reselect the last record? This function below uses the same method you described above and has been working for ages. What you posted above should work. What makes you say it is not working?

function refreshGrid(gridID) {
    var grid = $('#' + gridID).data('kendoGrid');
    var selectedItem = grid.dataItem(grid.select());
    grid.dataSource.read();
    grid.refresh();
    if (selectedItem != null && selectedItem.uid != null) {
        var row = grid.tbody.find('tr[data-uid="' + selectedItem.uid + '"]');
        row.addClass("k-state-selected");
        grid.select(row);
        grid.select(grid.table.find('tr').first());
    }
}

k-rebind="gridOptions"

This event will rebind the grid whenever gridOptions are changed.

发布评论

评论列表(0)

  1. 暂无评论