Perhaps I am not being clear. I know I can set the dataProvider within the
component. What I need to know is how I can either change the dataProvider
when the itemRenderer is called.
I want to use this itemRenderer in multiple grids. Each grid is to use the
itemRenderer with either a different dataProvider, or update the
dataProvider with different data.
So I'm trying to something like:
public function createPositionTable():void
{
_col1 = new DataGridColumn;
_col2 = new DataGridColumn;
_col3 = new DataGridColumn;
_col1.headerText= "Position";
_col1.dataField = "Description";
_col1.editable = true;
_col1.width = 100;
_col2.dataField = "Type";
_col2.headerText= "Type";
_col2.editable = true;
_col2.width = 50;
_col3.dataField = "levelCode";
_col3.headerText = "Level Code";
_col3.width = 150;
_col3.editable = false;
// HERE I SET THE itemRenderer - but want to use a different dataProvider
// OR AT LEAST UPDATE THE ORIGINAL DATAPROVIDER WITH NEW DATA
_col3.itemRenderer = new ClassFactory(comboR);
_col3.editorDataField = "levelCode";
_columns = new Array(_col1,_col2,_col3);
_datagrid = positionsGrid;
_datagrid.columns = _columns
_datagrid.sortableColumns = false;
_datagrid.dataProvider = objAdminTableGridDP;
_datagrid.dragEnabled = false;
_datagrid.dragMoveEnabled = false;
_datagrid.dropEnabled = false;
_datagrid.editable = true;
_datagrid.rowHeight = 30;
updateTablesButton.label = 'Update Positions Table';
}
public function createDepartmentTable():void
{
_col1 = new DataGridColumn;
_col2 = new DataGridColumn;
_col3 = new DataGridColumn;
_col1.headerText= "Position";
_col1.dataField = "Description";
_col1.editable = true;
_col1.width = 100;
_col2.dataField = "Type";
_col2.headerText= "Type";
_col2.editable = true;
_col2.width = 50;
_col3.dataField = "levelCode";
_col3.headerText = "Level Code";
_col3.width = 150;
_col3.editable = false;
// HERE I SET THE itemRenderer - but want to use different dataProvider
// OR AT LEAST UPDATE THE ORIGINAL DATAPROVIDER WITH NEW DATA
_col3.itemRenderer = new ClassFactory(comboR);
_col3.editorDataField = "levelCode";
_columns = new Array(_col1,_col2,_col3);
_columns = new Array(_col1,_col2,_col3);
_datagrid = positionsGrid;
_datagrid.columns = _columns
_datagrid.sortableColumns = false;
_datagrid.dataProvider = objAdminTableGridDP;
_datagrid.dragEnabled = false;
_datagrid.dragMoveEnabled = false;
_datagrid.dropEnabled = false;
_datagrid.editable = true;
_datagrid.rowHeight = 30;
updateTablesButton.label = 'Update Positions Table';
}
On 3/1/07, Alex Harui <[EMAIL PROTECTED]> wrote:
<mx:ComboBox dataProvider="{myLevels}" …
This should set you up to use the myLevels in every ComboBox.
The comboBox has built-in logic to set the selectedItem based on what it
sees in the data property. In your case you might want to override the data
setter and choose selectedIndex then.
FWIW, using VBox to wrap will be slower than ComboBox straight up.
------------------------------
*From:* [email protected] [mailto:
[EMAIL PROTECTED] *On Behalf Of *jwopitz
*Sent:* Thursday, March 01, 2007 12:01 PM
*To:* [email protected]
*Subject:* Re: [flexcomponents] Struggling with itemRenderer in DataGrid
First off, reinstate the VBox. The override the setter data
(value:Object). There you can either set the cb's dataProvider like cb.dp=
data.someObject
or if you are doing it in MXML, you can bind the dataprovider of the CB to
some expected property of the data property of the VBox.
Doing it via script is a bit tricky, because if your data value doesn't
contain the targeted property it will throw a runtime error.
On 3/1/07, *Steve Gustafson* <[EMAIL PROTECTED]> wrote:
OK, now I've gotten rid of the VBox, but still do not see how I can set a
different dataProvider to the comboBox, or dynamically set the
selectedIndex.
Again any help is greatly appreciated.
Steve
On 3/1/07, *Alex Harui* <[EMAIL PROTECTED]> wrote:
Your itemRenderer is not a ComboBox, it is a VBox containing a ComboBox.
The DataGrid sets the .data property on the VBox and you haven't written
the code to pass it on down to the ComboBox.
You can either write that code, or use ComboBox as the top-level tag so
you are really using a subclass of ComboBox as the renderer, which is the
recommended practice.
-Alex
------------------------------
*From:* [email protected] [mailto: [EMAIL PROTECTED]
*On Behalf Of *Steve Gustafson
*Sent:* Thursday, March 01, 2007 3:45 AM
*To:* [email protected]
*Subject:* [flexcomponents] Struggling with itemRenderer in DataGrid
Help.
I posted this on FlexCoders with no response, so I thought I would try
here too.
I'm trying to use an itemRenderer to create a comboBox in a DataGrid that
is being created with AS.
I can create the comboBox, but I am struggling with being able to change
the dataProvider for the rendered comboBox, and setting the selected index
on the comboBox.
The relevant code I am using is below.
Any help is GREATLY APPRECIATED as I am rapidly approaching a deadline.
Steve
public function createPositionTable():void
{
_datagrid = positionsGrid; // positionsGrid is an already created
DataGrid object
_col1 = new DataGridColumn;
_col2 = new DataGridColumn;
_col3 = new DataGridColumn;
_col4 = new DataGridColumn;
_col5 = new DataGridColumn;
_col1.headerText= "Position";
_col1.dataField = "Description";
_col1.editable = true;
_col1.width = 100;
_col2.dataField = "Type";
_col2.headerText= "Type";
_col2.editable = true;
_col2.width = 50;
_col3.dataField = "levelCode";
_col3.headerText = "Level Code";
_col3.width = 150;
_col3.editable = false;
_col3.itemRenderer = new ClassFactory(cbRender); // HERE IS WHERE I
AM CREATING THE COMBO BOX
_col3.editorDataField = "levelCode";
_columns = new Array(_col1,_col2,_col3);
_datagrid.columns = _columns
_datagrid.sortableColumns = false;
_datagrid.dataProvider = objAdminTableGridDP;
_datagrid.dragEnabled = false;
_datagrid.dragMoveEnabled = false;
_datagrid.dropEnabled = false;
_datagrid.editable = true;
_datagrid.rowHeight = 30;
updateTablesButton.label = 'Update Positions Table';
}
------------------------------------
cbRender.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="50"
height="25">
<mx:Script>
<![CDATA[
import mx.utils.ObjectUtil;
[Bindable]
public var myLevels:Array =
[{label:"Accounting", data:"accounting"},
{label:" Administator", data:"1"},
{label:"Programmer", data:"2"},
{label:"Vice President", data:"3"},
{label:"President", data:"4"},];
public var cboLevelID:String = '';
public function get setLevel():String {
return cboLevels.selectedItem.data;
}
]]>
</mx:Script>
<mx:ComboBox id="cboLevels" dataProvider="{myFolders}"/>
</mx:VBox>
--
justin w. opitz
617.771.6639
jwopitz(at)gmail.com