I have the need to refresh a DataGrid from a different component than where the DataGrid resides.
Component 1 has a datagrid.
Component 2 has some UI input fields.
I need component 2 to refresh the data in component 1's datagrid.
How is this possible?
if I do something like:
Component1.datagrid.dataprovider = null;
I get compiler errors. What is the safe way to access other components directly?
You can figure this out by using events..
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onCreationComplete();" xmlns:comp="comp.*">
private function onCreationComplete():void
private function refreshGrid(event:Event):void
comp1.dataGrid.dataProvider = null;
<comp:Component1 id="comp1" />
<comp:Component2 id="comp2" />
Now in your Component2 dispatch the refreshGridEvent event either on a button click or when your UI elements changes based on your requirement...this.dispatchEvent(new Event('refreshGridEvent')); and listen for the evet in manin mxml file and change the dataProvider of the dataGrid in Component1.
Note: This solution is if your both components are placed in the main mxml file. Is your structure is same as I mentioned in the code above..I mean
whether your two components are placed in the main mxml file.