dxDataGrid - How to refresh the widget

Girl_engineer picture Girl_engineer · Feb 9, 2017 · Viewed 13.6k times · Source

When ı clicked button, not working refresh.If the purpose is to add to the database buton button press to come to the screen. But is not updating. I created a datagrid with ajax. I also wrote the refresh function in ViewModel.What may be the reason for not renewing. My data is json.

Answer

Sergey picture Sergey · Feb 10, 2017

As Alex mentioned, your ajax happens only one. So, it's better to use the DataSource configuration object to load data:

var dataSource = {
    load: function() {
        var items = $.Deferred();
        $.ajax({
            type: "GET",
            url: "https://js.devexpress.com/Demos/WidgetsGallery/data/orderItems",
            success: function(result) {
                items.resolve(result.items);
            }
        });

        return items.promise();
    }
};

$("#gridContainer").dxDataGrid({
    dataSource: dataSource,
    //...
});

Then, if you call the refresh() method of dxDataGrid, data source will be reloaded.

Demo

Pay attention, the refresh method is useful if your data source is changing dynamically.