0
votes

I am trying to update the slickgrid data with preserving current page without page refresh . I am using ajax call which execute every 3 sec to update the grid data. I tried below given code but grid does not update. Below is my code

$.ajax({
                type: "POST",
                url: url,
                dataType: "json",
                data: {
                    input1:<dynamic value>,
                    input2:<dynamic value>,
                    input3:<dynamic value>
                },
                success: function (data) {
                    var bindData = [];
                    for (var i = 0; i < data.length; i++) {
                        var item = {
                            id: i,
                            col1: data[i].col1,
                            col2: data[i].col2,
                            col3: data[i].col3,
                        };
                        bindData [i]= item;
                    }
                    dataview.beginUpdate();
                    dataview.setItems(bindData );
                    dataview.endUpdate();
                    grid.invalidateRows();
                    grid.render();

                }

            })

I had also tried by removeing grid.invalidateRows(); but it does not work.

1
try adding grid.updateRowCount(); as well - Ben McIntyre
would be much more efficient using the existing data too eg. for (var i = 0; i < data.length; i++) { data[i].id = i; } - Ben McIntyre
I am getting all data again irrespetive of update. so data[i].id will true if there is no change . I might not get what you are tryign to convey. - Pavan

1 Answers

0
votes

I changed the sequence of statement and it works for me. Grid was not updating because i was invalidating the rows after setting the new data.

dataview.beginUpdate();
grid.invalidateAllRows();
dataview.setItems(bindData);
dataview.endUpdate();
grid.render();