Datagrid itemRenderer/itemEditor trouble
I have a datagrid in a Flex project, the data grid has an XML file as the source (contents below), now due to the way it is formatted (I cannot change this) some of the data I want to display is inside a tag that isnt at the initial array level. Here is the file:
<?xml version="1.0" encoding="utf-8" ?>
<Categories>
<Category>
<CategoryName>Cat 1</CategoryName>
<CategoryLink>http://www.google.com</CategoryLink>
<CategoryData>
<CategoryDescription>This is the description of category 1</CategoryDescription>
<CategoryHeader>My Category Title 1</CategoryHeader>
<CategoryNumber>1</CategoryNumber>
</CategoryData>
</Category>
</Categories>
I need to display CategoryName, CategoryLink, CategoryData.CategoryDescription, CategoryData.CategoryNumber.
Now I blindly dropped the datagrid into the project and bound it to the data source, I get the following returned for CategoryData:
[object CategoryData_type]
Not much use, but with what appears to be a hack I changed the code for the column to read dataField="CategoryData.CategoryDescription", and hooray it works. I didnt realise at the time that this was wrong, and when I dropped in an itemEditor things went wrong. When the datagrids load they display the correct data, but then when you try to edit any of the child property fields you get the following error:
ReferenceError: Error #1069: Property CategoryData.CategoryDescription not found on valueObjects.Category_type and there is no default value.
I have looked up the error and I realise that it means that there is no value for CategoryData.CategoryDescription, but if I can display it why can i not edit it! What do I have to do to make this work?
Anyway, here is the code, it shows the default bound datagrid, a second datagrid with the hack applied, and a third hacked datagrid with an itemRenderer and itemEditor on the number columns
Can you please take a look and tell me what I did wrong, well more to the point, if there is a doc that explains how to deal with XML like this then please point me at it.
I did try changing the return type for ANY of the columns, but this fails, I also tried a labelFunction, but again I can get the [object CategoryData_type] to display, but I get the null reference exception as the datagrid loads if I try to get to the child props.
Here is the Flex code:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:categories="services.categories.*"
minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
protected function dataGrid_creationCompleteHandler(event:FlexEvent):void
getDataResult.token = categories.getData();
protected function lftest(item:Object, column:GridColumn):String
var t:String = item.CategoryData;
return t;
]]>
</fx:Script>
<fx:Declarations>
<s:CallResponder id="getDataResult"/>
<categories:Categories id="categories"
fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"
showBusyCursor="true"/>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:DataGrid id="dataGrid" x="10" y="10" width="684"
creationComplete="dataGrid_creationCompleteHandler(event)" editable="true"
requestedRowCount="4">
<s:columns>
<s:ArrayList>
<s:GridColumn width="100" dataField="CategoryName" headerText="CategoryName"></s:GridColumn>
<s:GridColumn width="100" dataField="CategoryLink" headerText="CategoryLink"></s:GridColumn>
<s:GridColumn width="180" dataField="CategoryData" headerText="CategoryData"></s:GridColumn>
</s:ArrayList>
</s:columns>
<s:typicalItem>
<fx:Object CategoryData="CategoryData1" CategoryLink="CategoryLink1"
CategoryName="CategoryName1"></fx:Object>
</s:typicalItem>
<s:AsyncListView list="{getDataResult.lastResult}"/>
</s:DataGrid>
<s:DataGrid id="dataGrid2" x="10" y="147" width="684" editable="true" requestedRowCount="4">
<s:columns>
<s:ArrayList>
<s:GridColumn width="100" dataField="CategoryName" headerText="CategoryName"></s:GridColumn>
<s:GridColumn width="100" dataField="CategoryLink" headerText="CategoryLink"></s:GridColumn>
<s:GridColumn width="180" dataField="CategoryData" headerText="CategoryData"></s:GridColumn>
<s:GridColumn dataField="CategoryData.CategoryDescription" headerText="Desc"></s:GridColumn>
<s:GridColumn dataField="CategoryData.CategoryHeader" headerText="Head"></s:GridColumn>
<s:GridColumn dataField="CategoryData.CategoryNumber" headerText="Num"></s:GridColumn>
</s:ArrayList>
</s:columns>
<s:typicalItem>
<fx:Object CategoryData="CategoryData1" CategoryLink="CategoryLink1"
CategoryName="CategoryName1"></fx:Object>
</s:typicalItem>
<s:AsyncListView list="{getDataResult.lastResult}"/>
</s:DataGrid>
<s:DataGrid id="dataGrid3" x="10" y="284" width="684" editable="true" requestedRowCount="4">
<s:columns>
<s:ArrayList>
<s:GridColumn width="100" dataField="CategoryName" headerText="CategoryName"></s:GridColumn>
<s:GridColumn width="100" dataField="CategoryLink" headerText="CategoryLink"></s:GridColumn>
<s:GridColumn width="180" dataField="CategoryData" headerText="CategoryData"></s:GridColumn>
<s:GridColumn headerText="Number">
<s:itemRenderer>
<fx:Component>
<s:GridItemRenderer>
<s:NumericStepper value="{data.CategoryData.CategoryNumber}" />
</s:GridItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:GridColumn>
<s:GridColumn dataField="CategoryData.CategoryNumber" headerText="Number">
<s:itemEditor>
<fx:Component>
<s:GridItemEditor>
<s:NumericStepper value="{data.CategoryData.CategoryNumber}" />
</s:GridItemEditor>
</fx:Component>
</s:itemEditor>
</s:GridColumn>
</s:ArrayList>
</s:columns>
<s:typicalItem>
<fx:Object CategoryData="CategoryData1" CategoryLink="CategoryLink1"
CategoryName="CategoryName1"></fx:Object>
</s:typicalItem>
<s:AsyncListView list="{getDataResult.lastResult}"/>
</s:DataGrid>
</s:Application>
All and any advice welcome.
Shaine
One last try, I now know for sure that the data in the file is loading, I created a labelFunction on the CategoryDescription column that looks like this:
protected function dispData(item:Object, column:GridColumn):String
var t:Object = item.CategoryData;
var s:String = item.CategoryData.CategoryDescription;
return s;
Because it returns s, which I now know is undefined (which is the problem!) I managed to get a debug output. As you can see the value of t is the categorydata, and it appears to have the 3 values I need to get access to, but I have no idea how to do this. I also changed the function to read:
protected function dispData(item:Object, column:GridColumn):String
var t:Object = item.CategoryData;
var s:String = t.CategoryDescription;
return s;
But this undefines t and s! Very confused
this test2 (@d2e10a1)
item valueObjects.Category_type (@91f8a51)
[inherited]
column spark.components.gridClasses.GridColumn (@d61b239)
t valueObjects.CategoryData_type (@91f8c11)
[inherited]
_cacheInitialized_isValid false
CategoryDescription "This is the description of category 1"
CategoryHeader "My Category Title 1"
CategoryNumber "1"
_changedObjects mx.collections.ArrayCollection (@d5d9e41)
_changeWatcherArray [] (@cfab061)
_dminternal_model _CategoryData_typeEntityMetadata (@d4286a1)
_doValidationCacheOfCategoryDescription null
_doValidationCacheOfCategoryHeader null
_doValidationCacheOfCategoryNumber null
_doValidationLastValOfCategoryDescription null
_doValidationLastValOfCategoryHeader null
_doValidationLastValOfCategoryNumber null
_internal_CategoryDescription "This is the description of category 1"
_internal_CategoryHeader "My Category Title 1"
_internal_CategoryNumber "1"
_invalidConstraints [] (@ca50fd9)
invalidConstraints_der <setter>
_isValid false
isValid_der <setter>
managingService <setter>
_managingService null
_model _CategoryData_typeEntityMetadata (@d4286a1)
_validationFailureMessages [] (@cfab0b1)
s undefined
As always all help welcome.
Shaine
Message was edited after a oops moment by: ProcessEndNow
Similar Messages
-
TabIndex in DataGrid ItemRenderer Component
How to implement tabindex for the DataGrid ItemRenderer
Component?Any
idea Please."ravi_bharathii" <[email protected]> wrote
in message
news:gbv9ps$k6r$[email protected]..
> How to implement tabindex for the DataGrid ItemRenderer
Component?Any
> idea Please.
Is this what you wanted?
http://blogs.adobe.com/aharui/2008/08/datagrid_itemeditor_with_two_i.html -
Datagrid Column with complex itemRenderer / itemEditor
I have a datagrid with a custom component used as an itemRenderer / editor. The component has two view states (default is simply the text of my data and the second state contains my editor fields). I have is set up so that when an individual double-clicks on the cell of my datagrid the renderer changes view states to the editor view. This view contains a dateSelector component and two numeric stepper components that reflect a date (dateSelector) and the hour and minute in the two steppers. The problem I have is that I'm trying to control the view state based on when the user clicks outside of the editor. When the user is done editing the applicable field(s), I want the viewstate to change back to simply the text-view state and remove the editors.
I had this working except that whenever a user changed focus from say the dateSelector to one of the numeric steppers the view state changed prematurely. The editor view should stay in view until the datagrid cell loses focus. Any ideas???Hi Alex,
thanks for the response. I've looked at your example with the two text fields and can't seem to find a way to implement the same idea in my project. When the DG loads I don't want the editable fields to be displayed. I just want the user to see the text values. When the user double-clicks, I want the renderer to change to an editor and allow the user to make the necessary changes. I'm trying to switch view states within the renderer/editor to make this happen but can't seem to get the editor to switch back to a renderer when the cell in the DG loses focus. That's when I would like the switch to occur and not before. What happens now is that whenever one of the editable components loses focus the editor automatically switches back to a renderer and doesn't allow the user to navigate to any of the other editable components without double-clicking again. My editor uses a date selector and two numeric steppers. Any ideas? I'm still learing Flex and AS 3 so any help is greatly appreciated!! BTW... great blog.
Bill -
Datagrid itemRenderer - Help needed
I am having trouble getting this little bit of code working. I am trying to build an adhoc SQL generator, where the user selects the list of fields and then is able to set the WHERE criteria in a dataGrid, each row has field, criteria (ComboBox -equals, less than, etc), Low (editable), High (editable-Text or ComboBox lookup), AND/OR static ComboBox. Some of the field selections could be regular text based fields like Name and other fields selected could be lookup fields like State. I would like to be able to on rows that are TextInput render out a TextInput for LowValue and HighValue columns and for lookup fields render out a ComboBox with the dataProvider being set by a call to addComboData.
addComboData simply uses the myDataGrid.selectedItem.fieldname to determine which of the lookup table to use and assigns that collection to CBoxdataProvider. Seems simple enough but I have not been able to figure it out, some modifications seem to work, but only for a single dg cell others give me a list but does not populate lowValue but kill all other renderers. All help is appreciated.
<mx:DataGridColumn headerText="Low" rendererIsEditor="true" editorDataField="selectedItem" dataField="lowValue" textAlign="center">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalScrollPolicy="off" verticalScrollPolicy="off" horizontalAlign="center">
<mx:ComboBox initialize="outerDocument.addComboData()" dataProvider="{ outerDocument.CBoxdataProvider }" labelField="Description" textAlign="left" visible="{data.showCombo}" />
<mx:TextInput id="lowLabel" visible="{!data.showCombo}" />
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>Setting the selected item is not the same as a click. If you created the renderer correctly the style should change when you actually click on the item. (Does it?)
Or are you just trying to get the first row's background to be a different style when the datagrid first shows? (Initialization problem or not working at all?) -
Flex datagrid custom itemEditor - not returning data
Hi,
I am new to flex and this is a basic "How to" question.
I want to write custom item editors and renderers for a datagrid column.
I am facing two problems here
1) override public function get data() : Object is not working. however, if the type of the column is just text then override public function get text():String is working. Specifying editorDataField in the datagrid column definition is working for some types ex:Strings, Numbers
2) Nothing is working for slightly more complex types like an Image. even editorDataField is not working. Somewhere between the user editing the data (in the case of an image, edit = browse, select & load an image) and grid asking for data at itemEditEnd, the entire data loaded by the user is disappearing and it is returning null or some default value I'd set it to in override public function set data().
I am aware that datagrid reuses both editors and renderers but I dono how the data user has set is getting lost while the focus is on the same cell
I have tried to use getter setter for this custom data field mentioned in editorDataField but when I do so, nothing works.. it fails even for string type
It should be a simple thing to do and I am sure I am making some silly mistake .. please help me out. It has driven me nuts since today morning..
any pointers would be really appreciated.Hi,
thanks for the info. This is the understanding that I had after reading livedocs about item renderers.
I have given the correct editorDataField and dataField. But it isnt working..I am not sure what you mean by For complex renderers, make sure the property is properly implemented on the outer component.
The weird part is specifying editorDataField works for String and not for an image. I am pasting some of code (highlighting relevant parts) below.. please have a look and tell me what I am missing.
Datagrid :
<mx:DataGrid id="dg" editable="true" rowHeight="100" width="861" x="10" y="10" height="498"
dataProvider="{this.slideArray}">
<mx:columns>
<mx:DataGridColumn headerText="Text" width="100"
resizable="true" sortable="false"
itemRenderer = "mx.controls.Label"
itemEditor="editors.TextEditor"
dataField="text" editorDataField="myData"/>
<mx:DataGridColumn headerText="Image" width="600" resizable="true" sortable="false"
itemRenderer="mx.controls.Image"
itemEditor="editors.ImageEditor"
dataField="image" editorDataField="myData"/>
</mx:columns>
</mx:DataGrid>
Text editor :
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true"
initialize="initEditor()">
<mx:TextInput id="edit" width="{this.width}" height="{this.height}"/>
<fx:Script>
<![CDATA[
import domain.Slide; // has two properties : public var text : String and public var image : mx.controls.Image;
override public function set data(value:Object):void{
super.data = value;
this.edit.text = (value as Slide).text;
public var myData : String; // editor data field
import mx.binding.utils.BindingUtils;
private function initEditor():void{
BindingUtils.bindProperty(this,"myData", this.edit, "text");
]]>
</fx:Script>
</s:MXDataGridItemRenderer>
ImageEditor :
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="100%" height="100%"
focusEnabled="true" contentBackgroundColor="#F1B4B4">
<mx:Image id="img" x="0" y="0" width="200" height="200" />
<s:Button label="Click to Add Image" id="addImageButton" click="addImageButton_clickHandler(event)"
x="0" y="{this.height - addImageButton.height}"/>
<fx:Script>
<![CDATA[
import domain.Slide;
public var myData : Image; //editor data field
override public function set data(value:Object):void{
super.data = value;
if( (value as Slide).image != null) this.img.source = (value as Slide).image.source;
protected function addImageButton_clickHandler(event:MouseEvent):void
// select image from file system
var imgFilter : FileFilter = new FileFilter("Images","*.jpg;*.png;*.gif");
var fileRef : FileReference = new FileReference();
fileRef.addEventListener(Event.SELECT, fileSelectHandler);
fileRef.addEventListener(Event.OPEN, fileOpenHandler);
fileRef.addEventListener(Event.CANCEL, fileCancelHandler);
fileRef.browse([imgFilter]);
function fileRefSelectListenerUp(e:Event):void{}
private function fileSelectHandler(event : Event):void{
var fileRef : FileReference = event.target as FileReference;
fileRef.addEventListener(Event.COMPLETE, fileLoadHandler);
fileRef.load();
private function fileLoadHandler(event : Event) : void{
var fileRef : FileReference = event.target as FileReference;
this.myData = new Image;
this.myData.name = fileRef.name;
this.myData.source = fileRef.data;
this.img.source = fileRef.data;
private function fileOpenHandler(event : Event):void{}
private function fileCancelHandler(event : Event):void{}
]]>
</fx:Script>
</s:MXDataGridItemRenderer> -
Datagrid itemrenderer causing weird data scrolling behaviour
I have a datagrid bound to an array for editing and viewing.
I have a listener for an ItemEditEnd event which looks at the
input, chomps any whitespace and writes back to the itemrenderer
the updated string. But... if I then reload the data into the
dataprovider the datagrid doesn't render it properly because it
retains a memory of the previously edited value and re-displays it
on the line below where it was. So repeatedly reloading the data
causes edited values to magically scroll themselves downwards in
the datagrid!
I gues this is something to do with itemrenderers being
recycled, but I have no idea how to code around it. Any help would
be gratefully received. A simplified mock up of the problem is
attached.
Many thanks in advance,
SteveNothing new in that article, maybe as the series
progresses...
I have a found a hack around this but it's not the way I want
to do it. If I add the itemeditend event listener with a very low
priority (-100) so it gets executed after flex has already updated
the datagrid I can interact directly with the data, instead of the
itemeditor/renderer before the data is updated. This means I can't
do a preventUpdate() and force the user to correct the input so is
not ideal, but it works in this limited application.
I did find this:
http://livedocs.adobe.com/flex/3/html/help.html?content=celleditor_8.html
which has exactly the same case of needing to modify data sent back
from an itemeditor. It pokes the modified data back to
TextInput(myGrid.itemEditorInstance).text which is the same object
as my (event.itemRenderer as TextInput).text. Doesn't work.
I attach my code for anyone else struggling with this. If
anyone has a better solution I'd love to see it.
Steve -
Showing/hiding images in a DataGrid ItemRenderer flex
Hi,
I have datagrid in that i have a itemRenderer in which i am loading images. What i need to do is i have to hide one or two images in tha datagrid.
For example if i have ten rows of data with image means i need to hode 4 rows images. Please any body help me.
Regards,
Jayagopal.
Message was edited by: Jayagopal FlexTry adding visible='{data.participant_count>0}' to your HBox or Component
-K -
Datagrid itemRenderer custom component formatting
OK, so this is my first attempt at an itenRenderer. This works below, but I have to imagine there is an easier way. There is also a problem with below, where the changed field (datafield=side) after the itemRenderer is applied, the text is all out of format, and there is a kind of selection on row one of that column. Obvisouly, though the translation is happening, I'm either overidding the wrong thing, or I'm doing something totally wrong.
Goal..... Show in the datagrid, the three colums below from date provided from elsewhere. (This all works), but in the 'side' data it comes in, in raw form as either an 'a' or 'b' or 'both', and I'm trying to display that as something more user friendly. So when both is read it changes it to 'No'.
Any help. This seems really easy, though I can't understanading hy my custom function screws with the cell selection, and formating?
---Main program---
<mx:DataGrid x="10" y="9" width="199" height="147" id="gdimmer_checkChannel" dataProvider="{ current_rack.getItemAt(0).rackLevels }"
change="dimmerCheckCurrentSelection(event);"
sortableColumns="false"
selectedIndex="{ current_rack.getItemAt(0).currentCheckIndex }" >
<mx:columns>
<mx:DataGridColumn headerText="UDN" dataField="udn"/>
<mx:DataGridColumn headerText="DD" dataField="side" editable="false" itemRenderer="renderers.DataGridDDSide"/>
<mx:DataGridColumn headerText="Circuit" dataField="circuit"/>
</mx:columns>
</mx:DataGrid>
--- Component Below ---
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true">
<s:Label id="lblData" text="{dataGridListData.label}" />
<fx:Script>
<![CDATA[
override public function set data(value:Object):void
if (value.side == 'both') { lblData.text = " No" };
if (value.side == 'a') { lblData.text = " a" };
if (value.side == 'b') { lblData.text = " b" };
]]>
</fx:Script>
</s:MXDataGridItemRenderer>See the latest post on my blog. You also need to set super.data in the data
setter.
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui -
Move focus from one to another itemRenderer inside DataGrid itemRenderer
I have a mx: DataGrid with 4 columns that have a itemRenderer with the following settings:
- Mx:DataGrid:
<code>
<mx:DataGrid id="itensPedidoCompraList"
width="100%"
height="120"
dataProvider="{ model.pedidoCompra.itens }"
editable="true"
itemEditEnd="itensPedidoCompraList_itemEditEndHandler(event)">
</code>
- Mx:DataGridColumn:
<code>
<mx:DataGridColumn headerText="{resourceManager.getString('cadastroPedidoCompra', 'ident.PercentualDesconto') }"
width="60"
textAlign="right"
rendererIsEditor="true"
editorDataField="data">
<mx:itemRenderer>
<fx:Component>
<mx:Canvas>
<input:NumberInput width="55" number="@{ data.percentualDesconto }"/>
</mx:Canvas>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</code>
The user clicks on the line of the grid and click on the column to edit.
After him change or add value, ENTER key and have to move the focus to another column in the same line.
The way I'm doing, is moving to the column below.
What is the best way to do to move to the right column?
thank youTry adding a capture phase event listener to DataGrid for keyDown and changing the key from ENTER to TAB
-
Enable disable linkbar links in datagrid itemrenderer.
Hi All,
I have to show the linkbar in datagrid column as a renderer and enable and disable the links according to attached documents codes.
here are my sample code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var arrColl:ArrayCollection = new ArrayCollection();
public function init():void{
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
arrColl.addItem(["1,2,3","1,2"]);
arrColl.addItem(["1,2,3", "1,3"]);
]]>
</mx:Script>
<mx:DataGrid id="dg" dataProvider="{arrColl}" width="200" height="500" x="510" y="168" >
<mx:columns>
<mx:DataGridColumn itemRenderer="assets.components.linkbarItemRenderer" />
</mx:columns>
</mx:DataGrid>
</mx:Application>
My item renderer linkbarItemRenderer.mxml as
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" creationComplete="init();" >
<mx:Script>
<![CDATA[
import mx.controls.LinkButton;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
[Bindable] public var arrColl : ArrayCollection = new ArrayCollection();
public var arrDocType : ArrayCollection = new ArrayCollection([{data:"1" , label:"AP"},{data:"2" , label:"AR"},{data:"3" , label:"BOL"}]);
public var attDoccodes : Array;
public function init():void
try
var requiredDoc :String = data[0];
var attachDoc : String = data[1];
var reqDocCodes :Array = requiredDoc.split(",");
attDoccodes = attachDoc.split(",");
if(reqDocCodes != null)
//add the links of required documents.
for(var i:int = 0 ; i<reqDocCodes.length; i++ )
var obj:Object = new Object();
for(var j : int = 0; j < arrDocType.length; j++)
if(arrDocType.getItemAt(j).data == reqDocCodes[i])
obj.label = arrDocType.getItemAt(j).label;
obj.data = reqDocCodes[i];
arrColl.addItem(obj);
callLater(enableDisalbeLinks);
catch(error:Error)
Alert.show("error ::"+error.getStackTrace());
public function enableDisalbeLinks():void
try
//disable all links first
for(var q:int=0; q< arrColl.length; q++)
LinkButton(linkBarId.getChildAt(q)).enabled = false;
if(attDoccodes != null)
for(var k:int = 0; k<attDoccodes.length; k++)
for(var l:int = 0 ; l<arrColl.length; l++)
if(arrColl.getItemAt(l).data == attDoccodes[k])
LinkButton(linkBarId.getChildAt(l)).enabled = true;
catch(error:Error)
Alert.show("error ::"+error.getStackTrace());
]]>
</mx:Script>
<mx:LinkBar id="linkBarId" dataProvider="{arrColl}" />
</mx:HBox>
It renderes the link in correct form in datagrid first time.when i scroll the datagrid the rows are miss up with each other and links are not shown propers in enable/disable format.
Thanks,
Amol.Hi All,
It was my fault. Got it work now.
When I redirect to PR, it also calls my page initialization method and clear all data. I added a parameter and issue resolved.
Thanks & Regards,
KJ -
Ellipsis (...) in dataGrid itemRenderer
If you want a line of text in a datagrid cell to end with an ellipsis (...) when it's too long for its cell, you can set the column's item renderer to be "mx.control.Label" and that works. The entry looks like this:
Here is my line of dat...
But here's my problem.
I have created my own item renderer which is an HBox containing an image and a label. But the label doesn't truncate with the ellipsis ... when the data is too long, it simply chops the end off the displayed text.
So my question is this. How can I get the ellipsis ... to appear for the label in my item renderer? I'm using a datagrid with scaleable column widths so I can't set a fixed width on the label which would work, I know.
Cheers,
NeilThanks for your suggestion.
It didn't work but inspired me to play around with minWidth and maxWidth.
What I eventually got to work was:
maxWidth="
{this.width-28}"
...on the Label in the HBox. I'm assuming that "this" here refers to the ItemRenderer.
I had to put in the "-28" bit or it wouldn't do it. If you want more padding on the right of the ellipsis (so it doesn't hit the edge of the cell) increase the 28 to something higher. Use a lower value for less padding.
Hope this helps someone else like it did me.
Cheers,
Neil -
Problem with Datagrid itemrenderer with a Datagrid
Hi all,
I have this kind of a structure. I try to use a datagrid item renderer in a data grid column. However when I try to move rows inside the same datagrid I experience a problem. When my datagrid loads first it seems correct, but when I drag and drop a row in the same datagrid inner datagrids start to be drew in wrong rows. I checked the DB but there are no mistakes in DB records. Problem is with rendering. I suppose inner datagrids trying to draw to early or datagrid component is trying to reuse the itemrenderer. I could not find any solutions for that. Any help will be greatly appreciated..
<mx:DataGridColumn width="130" editable="false"
headerText="{resourceManager.getString('resources', 'acl.content')}">
<mx:itemRenderer>
<mx:Component>
<ACLInnerDataGrid rowCount="3" dragEnabled="true" dropEnabled="false"
x="0" y="0" editable="true" dragInitiatorId="catGrid"
filterGroupName="content" remoteDestination="zend"
remoteSource="ACLFilterParamService" showHeaders="false"
creationComplete="this.init();">
<columns>
<mx:DataGridColumn dataField="id" editable="false" visible="false"/>
<mx:DataGridColumn dataField="ruleId" editable="false" visible="false"/>
<mx:DataGridColumn dataField="filterKey" editable="false" visible="false"/>
<mx:DataGridColumn dataField="param" editable="false" visible="false"/>
<mx:DataGridColumn dataField="name" editable="true"/>
</columns>
</ACLInnerDataGrid>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
Thanks in advance.I have attached the item renderer component source code.
-
I have created a datagrid which has suppose 4 columns out of which 1 has an option of setting as favorite just like we have in our every mail servers (gmail, yahoo, outlook, etc). I have used a linkbutton as an item renderer and its toggle property as true. so wenever i click on it its getting selected and i have used skin for selected and normal state which is a star.
The problem is that when data length exceeds and scrollbar comes in datagrid and whenever i scroll down and up the stars which are not selected are getting selected or in some scenarios the whole column stars get selected.
How to get rid of this problem ?Can I see the itemrenderer code. I'm assuming that you aren't clearing the values from previous objects in you
override protected function set data( value:Object ):void call.
Sincerely ,
Ubu/ -
DataGrid itemrenderer with switch statement
Hi,
I have datagrid control with this columns
<mx:DataGrid id="dgvParagraphs" >
<mx:columns>
<mx:DataGridColumn dataField="type" headerText="Type"/>
<mx:DataGridColumn dataField="title" headerText="Title"/>
<mx:DataGridColumn dataField="content" visible="false"/>
</mx:columns>
</mx:DataGrid>
Under type column I have values from 1 to 6. Each number presents type of content. I have icons for each type. I would like to show icon instead of just number. I know this can be done using itemrenderes but I don't know how to accomplish this.If this post answers your question or helps, please mark it as such.
Greg Lafrance
www.ChikaraDev.com
Flex Development and Support Services
You might see issues with this code during scrolling, as DataGrid recycles itemRenderers, but in that case the icon information must be in the data.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
public function getImageSource(item:Object):String{
var retVal:String;
switch(uint(item.type)){
case 1:
retVal = "black.png";
break;
case 2:
retVal = "blue.png";
break;
case 3:
retVal = "gray.png";
break;
case 4:
retVal = "green.png";
break;
case 5:
retVal = "purple.png";
break;
case 6:
retVal = "red.png";
break;
trace(retVal);
return retVal;
]]>
</mx:Script>
<mx:DataGrid id="dgvParagraphs" dataProvider="{dataXML..item}">
<mx:columns>
<mx:DataGridColumn dataField="type" headerText="Type" width="50">
<mx:itemRenderer>
<mx:Component>
<mx:Image source="{outerDocument.getImageSource(data)}" horizontalAlign="center"/>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="title" headerText="Title" width="100"/>
<mx:DataGridColumn dataField="content" visible="false"/>
</mx:columns>
</mx:DataGrid>
<mx:XML id="dataXML" xmlns="">
<data>
<item>
<type>2</type>
<title>My Title 1</title>
<content>Content 1</content>
</item>
<item>
<type>5</type>
<title>My Title 2</title>
<content>Content 2</content>
</item>
<item>
<type>3</type>
<title>My Title 3</title>
<content>Content 3</content>
</item>
<item>
<type>1</type>
<title>My Title 4</title>
<content>Content 4</content>
</item>
<item>
<type>4</type>
<title>My Title 5</title>
<content>Content 5</content>
</item>
<item>
<type>6</type>
<title>My Title 6</title>
<content>Content 6</content>
</item>
<item>
<type>2</type>
<title>My Title 7</title>
<content>Content 7</content>
</item>
<item>
<type>1</type>
<title>My Title 8</title>
<content>Content 8</content>
</item>
<item>
<type>4</type>
<title>My Title 9</title>
<content>Content 9</content>
</item>
<item>
<type>5</type>
<title>My Title 10</title>
<content>Content 10</content>
</item>
<item>
<type>2</type>
<title>My Title 11</title>
<content>Content 11</content>
</item>
</data>
</mx:XML>
</mx:Application> -
Datagrid itemRenderer dynamic values
While working on an application I came across the following
problem. I've got a view with a datagrid, where I have several
columns. Each column needs 2 values displayed beneath each other in
one cell. You make an itemRenderer with 2 labels inside a VBox.
Easy so far. However since this scenario repeats several times it
seems counterproductive to make an itemRenderer for each cell. How
can I make the text property for the labels change for each cell
instead of being static in their values.
Thx in advance.Your description of your requirements and your sample code do
not paint a clear enough picture.
Your dataProvider has 4 pieces of data: batchId,
bookingNumber, valueDate, immsBranch. Your current itemRenderer
references two of those pieces of data, and you say you want to
reference the other two. You can do that easily like this:
<mx:Label text="data.valueDate"/>
<mx:Label text="data.immsBranch"/>
A basic question: will your DataGrid have two rows for each
set of 4 pieces of data? If so then I understand your problem. If
not, then you must clarify exactly how and when you would like the
4 pieces of data shown in your DataGrid.
In any case, you probably need a Repeater, and then need to
figure out how to get at the right data at the right time in the
Repeater.
See this FB 3 help topic and its sub-topics:
Dynamically Repeating Controls and Containers
Also search for this in the FB3 help to see the API:
mx.core.Repeater
You can define a listener for the Repeater for the Repeat
event to specify processing for each iteration of the
repeater.
Maybe you are looking for
-
I am not receiving group messages from others, but I cannot send more than 1 message at a time. Ive added them into a group but it only sends to the person first on the recipients. They do have iphones and samsung galaxys. I have tried to download a
-
Dear BPM experts, I would like to raise few questions and get some guidance from experts working on OBPM for long time... 1) We have a business process where data is received from external source and has to be evaluated before we could determine if a
-
No momentum scrolling in Acrobat Pro 9?
Has anyone else noticed that there's no momentum scrolling in Acrobat Pro 9?
-
Is there a way to set an Out of Office condition and message on an EAS Outlook account on the Pre Plus? I had this feature on my old Treo and it was useful. Please advise if there is a way to set Out of Office through the Pre Plus. If not, it would
-
Random "WSAECONNREFUSED: Connection refused" error
hello, we're connecting to sap using logon groups and randomly we get this error <i>TmConnect2: handle = 0 sncname = [] set snc-mode OFF TmISncSetOptions: set tm_mode for 0 to TM_SNC_OFF disp service: sapdp00 TmIGetName: no DISPLAY set NiMyH