3

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>
Girl_engineer
  • 145
  • 1
  • 2
  • 20
  • 1
    What's the purpose of calling the refresh method for the data grid instance? Do you change a dynamically changed data source ? What do you expect from calling the refresh method? If you initialize the grid in your ajax call just once, it does not make any sense to refresh the grid. – Alex Skorkin Feb 10 '17 at 11:07
  • @AlexSkorkin Can I ask you a question? – Girl_engineer Feb 23 '17 at 05:36

1 Answers1

5

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.

Sergey
  • 5,396
  • 3
  • 26
  • 38
  • This method is not working. Only ajax works. how will I do? – Girl_engineer Feb 10 '17 at 12:58
  • > What do you expect from calling the refresh method? – Sergey Feb 10 '17 at 13:04
  • I will briefly explain. I delete the line with the dialog on the screen when I press on the line. But the line stays there. But it does not immediately fall on the screen. I made a refresh button for this. Go on the screen in the press. (It is not in my code) – Girl_engineer Feb 10 '17 at 13:10
  • It looks like you have a bug here - "I delete the line with the dialog on the screen when I press on the line. But the line stays there." Be sure you delete a row correctly. – Sergey Feb 10 '17 at 13:14
  • So if you look at it, I do it with ajax. I get the row id and send it with ajax. It is done with web service. I'm just sending the row id and seeing the length of the data goes down. – Girl_engineer Feb 10 '17 at 13:19
  • 1
    Take a look at this [example](https://jsfiddle.net/sergfry/f8rq82af/2/). I use local data, but it makes not difference. BTW, dxDataGrid has built-in editing functionality - https://js.devexpress.com/Documentation/16_2/ApiReference/UI_Widgets/dxDataGrid/Configuration/editing/#allowDeleting – Sergey Feb 10 '17 at 13:33
  • 1
    Thank you for your interest. I will try to reach the end with what you gave. – Girl_engineer Feb 10 '17 at 13:46