dxDataGrid - How to refresh the widget

偶尔善良 提交于 2019-12-22 12:17:16

问题


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.

$.ajax({
        type: "GET",
        url: "https://js.devexpress.com/Demos/WidgetsGallery/data/orderItems"
        success: function (msg, result, status, xhr) {
        var obj = jQuery.parseJSON(msg);
        $("#gridContainer").dxDataGrid({
        dataSource: obj,
        filterRow: {
        visible: true}});}});
        var viewModel = {
        refresh: function () {        
        var dataGrid = $('#gridContainer').dxDataGrid('instance');
        dataGrid.refresh();}};
return viewModel;
<div data-options="dxView : { name: 'dd',disableCache: true } " >
   <div data-bind="dxCommand: { icon: 'refresh', id: 'save', onExecute: refresh }"></div>
     <div  data-options="dxContent : { targetPlaceholder: 'content' } " >
       
         <div  id="gridContainer"></div> 
        
            </div>
</div>

回答1:


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.



来源:https://stackoverflow.com/questions/42134801/dxdatagrid-how-to-refresh-the-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!