PDA

View Full Version : help with loading grid with dynamic data



beekay
18 Jan 2007, 2:32 AM
Hi,

I am trying to load a default grid with data based on selections from a dropdown box(Default dataModel). Everything seems to work fine but then each time a new option is chosen from the dropdown box the rows get appended to the existing rows in the grid. I want a fresh grid with only appropriate rows corresponding to the selected option.

I've tried getting the rowcount from the datamodel, loop through it and delete it one by one and add afresh. Even that doesnt seem to work. Whats the right way to achieve this?

Thanks

Animal
18 Jan 2007, 3:10 AM
In your DataModel, change the data property to the new data array, and fire the "datachanged" event.

Should work :!: :?:

beekay
18 Jan 2007, 3:34 AM
Thank you. But could you please show me a code snippet on how to do this. Jus the two lines on how i set the property and how i should fire the event and what do i need to pass as parameters in case i should. Will i need a listener also that will handle this?
Thank you again

Animal
18 Jan 2007, 4:13 AM
What? have you even peeked at the code? Set a property? Don't know how to do that? Read, try, experiment!

Anyway:



myModel.data =[["foo", "bar"],["bletch", "blivit"]];
myModel.fireTableDataChanged();


You don't listen for that event, the GridView does. That's how it works. It plugs itself into the DataModel and subscribes to it's events. Look at the code, it's informative:

GridView.js contains:


plugDataModel : function(dm){
dm.on('cellupdated', this.updateCell, this, true);
dm.on('datachanged', this.renderRows, this, true);
dm.on('rowsdeleted', this.deleteRows, this, true);
dm.on('rowsinserted', this.insertRows, this, true);
dm.on('rowsupdated', this.updateRows, this, true);
dm.on('rowssorted', this.handleSort, this, true);
},