3.2.0

Refresh data while maintaining grid state

I have seen several threads on this topic, but none of the solutions I have seen have solved my issue, or perhaps I have not implemented the suggested solutions correctly.

I am using a grid whose data comes from an xml file and am trying to implement a refresh method which will reload the data while keeping the currently selected record, scrollbar positions and sort options.

What I have found is this:

- Using grid.refresh() keeps the selected record, scrollbar positions and sort options, but does not reload the data therefore the grid does not reflect changes to the data.

- Using table.request() reloads the data and correctly reflects changes to the data, but resets the grid state losing the selected record, scrollbar positions and sort options.


I tried Alex's old solution offered in this thread /javascript.forum.839.4/calling-refresh-when-scrolled-down.html
but I likely didn't implement it correctly since it did not solve the issue either.

What is the preferred method to refresh the data in a grid loaded from an xml file while not losing the current state of the grid?


Below are simplified snippets of my code:


var table = new AW.XML.Table;
var grid = new AW.UI.Grid;
table.setURL("server_xml.asp");
table.request();
grid.setCellModel(table);


function refreshData()
{
// This refreshes data but resets grid state
table.request();

// This maintains grid state, but does not refresh data
grid.refresh();
}
David
May 16,
here is the code of the default response callback (source/lib/xml/table.js) -
obj.response = function(xml){
            this.setXML(xml);

            if (this.$owner) {
                  this.$owner.clearScrollModel();
                  this.$owner.clearSelectedModel();
                  this.$owner.clearSortModel();
                  this.$owner.clearRowModel();
                  this.$owner.setRowCount(this.getCount());
                  this.$owner.refresh();
            }
      };


You may replace it after the first call with something like

obj.response = function(xml){
            this.setXML(xml);
            this.$owner.refresh();
      };


However there are many questions - what happens if you have a different number of rows (how do you identify previously selected rows) etc.

Another approach is implemented in /examples/grid data-realtime/quotes.htm. The sample code uses CSV files, but it will work with XML exactly the same way.

Alex (ActiveWidgets)
May 16,

This topic is archived.

See also:


Back to support forum