How to refresh data in a bwu_datagrid

97 Views Asked by At

I'm attempting to refresh an existing datagrid in the following manner, but that results in rendering errors, like rows still appearing. What is the appropriate way to do this?

void onData( Map<String,Data> data_ ){
  if( identical(data,data_) ) return;
  data = data_;
  if( provider == null ){
    provider = new MapDataItemProvider();
    grid.setup(dataProvider: dataProvider, columns:columns, gridOptions: gridOptions);
  }else{
    dataProvider.items.clear();
  }
  data.forEach( (k,v) => provider.add( toMapped(k,v) );
  grid.render();
}
2

There are 2 best solutions below

0
On BEST ANSWER

invalidateAllRows() is another way to notify the grid that the data has changed.

0
On

Reading the DataView example, it appears there are a few calls other than render() to be made.

  • grid.invalidateRows(e.changedRows);
  • grid.updateRowCount();
  • grid.invalidateAllRows()

but the best way is probably invalidate() Duh.

After adding invalidate(), the grid was redrawing correctly...

void onData( Map<String,Data> data_ ){
  if( identical(data,data_) ) return;
  data = data_;
  if( provider == null ){
    provider = new MapDataItemProvider();
    grid.setup(dataProvider: dataProvider, columns:columns, gridOptions: gridOptions);
  }else{
    dataProvider.items.clear();
  }
  data.forEach( (k,v) => provider.add( toMapped(k,v) );
  grid.invalidate();
}

Code for Invalidate from github bwu_datagrid

void invalidate() {
  updateRowCount();
  invalidateAllRows();
  render();
 }