Datagrid lableFunction
Is there any way of knowing what row a labelFunction
function is currently working on, so
<mx:DataGridColumn headerText="Total" dataField="TOTAL_PRICE" labelFunction="calculateTotalPrice" editable="false" minWidth="50"/>
protected function calculateTotalPrice(item:Object, column:DataGridColumn):String
// in here i need to know the row
Oups, sorry about that. I thought the owner property was public, but its scope is actually mx_internal.
For me there's two solutions :
1- The best would be to use an itemRenderer instead of a labelFunction. If your itemRenderer extends an UIComponent you will be able to access its owner property, which will be the DataGrid.
2- Kind of dirty, but you could extend the DataGridColumn class and implement a public getter on the DataGrid's dataprovider :
import mx.core.mx_internal;
use namespace mx_internal;
public function get gridProvider():Object {
return owner.dataProvider;
And access it in your labelFunction.
The choice is yours...
Similar Messages
-
Formatting a column in a datagrid
If I want to format some data in a column of a datagrid is
there a preferred way of doing that? I have used both an
itemRenderer and a labelFunction
Is there a preference to one or the other?lableFunction can be used when the tweaking required is very
trivial and you want to modify some text getting displayed.
(custom) itemRenderers can be used when we want to display
something complex within a cell like few controls, icons, labels,
links etc. -
Datagrid Image Renderer Broken in CS SDK but not Flex project
Within a Photoshop Extension, I have a DataGrid which has an inline custom image renderer whose dataprovider is an ArrayCollection called "photos" representing a list of photos and some metadata properties. One of the properties "fileName" is concatenated with a path to a thumbnail image such as source="{'LR_AUTO/imported/thumbs/' + data.fileName}".
The dataprovider is bound to a LCDS DataService. When the extension is first launched, the dataservice initializes the dataprovider with the existing values for the "photos" arraycollection. The thumbnail images are correctly shown.
However, when the DataService receives a new row and updates the photos dataprovider, the datagrid's new row shows a broken image for the thumbnail even though the path is correct. I have dumped the photos dataprovider and verified that all information is correct. When I close Photoshop and relaunch it from Flash Builder, once again LCDS initializes the photos ArrayCollection and THEN the thumbnail that previously showed as broken show up correctly.
I have a ColdFusion Directory Watcher Gateway that watches a directory where Lightroom auto-imports images from a tethered capture session. When the camera sends Lightroom a new image, the new image is processed by Lightroom and moved to a target directory, and since ColdFusion's Directory Watcher is watching that targeted directory, ColdFusion will create a thumbnail image in a subfolder and notifiy LCDS that of the new image and related metadata.
*** This is the interesting part *** When Lightroom places new images in the target directory, this is propogated to the Photoshop Extension's datagrid, and the new row shows up as described earlier, showing a broken image for the thumbnail. BUT, instead of Lightroom, if I manually copy images to the folder where ColdFusion is watching, then exact same code path is exectuted and in the Photoshop Datagrid the new row appears and THE THUMBNAIL IMAGE shows up correctly.
The difference seems to be only in how the images are put in the original target location. The problem is when Lightroom puts them there, but it works when I put them there as a user.
*** More Interesting Info *** I have the Flex code for the Photoshop Extension duplicated in a standalone, non-CSSDK project using Flex 3.4 which I launch in a browser. I have mirrored the code in the Photoshop extension, but in this manner, the problem does not exist. With plain Flex 3.4 in a browser, whenever LCDS notifies the datagrid of a new photo record, the datagrid's new row ALWAYS shows the thumbnail correctly.
A primary difference in how the thumbnail image is rendered is that in a browser, the Flex 3.4 project accesses the image assets over the network, however, in the Photoshop Extension, the image asset WITH THE SAME RELATIVE PATH is accessed over the local file system.
source="{'LR_AUTO/imported/thumbs/' + data.fileName}"
So in the case of the browser, this path is a relative URL and the image is retrieved over HTTP, however, in the PS Extension, the same path represents a file system path relative to the project folder.
Unfortunately, because the Flash Player (including APE) cannot access BOTH the network and the local filesystem, so I cannot change the Extension to use network access.
** The important part to remember is that when I stop the Flash Builder debug session and close Photoshop, then relaunch the debug with Photoshop, then all the images show up correctly in the Extension.
Your advice is appreciated.
Thank you!
Steve
====================================================
Environment
====================================================
Photoshop CS5 Extended 12.01 x32
Flash Builder 4
CS SDK 1.02
Extension Builder SDK 3.4
MacBook Pro / OS X 10.5 / Intel Core 2 Duo 2.66 GHz / Procs: 1 / Cores: 2 / Memory: 8 GB
App configured for Photoshop CS5 and Photoshop CS5 Extended
====================================================
NewsAgencyPhotoshop.mxml
====================================================
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="com.stevenerat.news.*"
horizontalScrollPolicy="off" verticalScrollPolicy="off" verticalGap="0"
layout="vertical" horizontalAlign="left" backgroundColor="#353535"
historyManagementEnabled="false"
creationComplete="init();">
<mx:Script>
public function handlePhotoClick(data:Object):void {
this.PreviewImageWindow = PreviewImage(PopUpManager.createPopUp(this,PreviewImage,true));
var filePath:String = data.dirPath + data.fileName;
PreviewImageWindow.addEventListener("imageOpenEvent",imageOpenListener);
PreviewImageWindow.addEventListener("imageCloseEvent",imageCloseListener);
PreviewImageWindow.addEventListener("imageSavedEvent",imageSaveListener);
PreviewImageWindow.setFileName(data.fileName);
PreviewImageWindow.setFilePath(filePath);
PreviewImageWindow.y = 0;
PreviewImageWindow.x = 0;
]]>
</mx:Script>
<mx:ArrayCollection id="photos"/>
<NewsPhoto/>
<mx:DataService id="ds" destination="NewsAgencyPhotos" autoSyncEnabled="true" autoCommit="true" conflict="conflictHandler(event)"/>
<mx:Label text="News Agency Photos" fontSize="20" paddingBottom="30"/>
<mx:Label text="Available Images" fontSize="15"/>
<mx:DataGrid id="photoIPTC" dataProvider="{photos}" editable="true" width="220" rowCount="5" rowHeight="75" wordWrap="true">
<mx:columns>
<mx:DataGridColumn headerText="id" dataField="fileName" width="40" editable="false" sortDescending="true"/>
<mx:DataGridColumn dataField="psLock" width="65" headerText="Status" editable="false" editorDataField="value">
<mx:itemEditor>
<mx:Component>
<mx:ComboBox editable="false">
<mx:dataProvider>
<mx:String>New</mx:String>
<mx:String>Open</mx:String>
<mx:String>Edited</mx:String>
</mx:dataProvider>
</mx:ComboBox>
</mx:Component>
</mx:itemEditor>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="Photo" dataField="fileName" width="80" editable="false">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="center" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:Image click="outerDocument.handlePhotoClick(data);" source="{'LR_AUTO/imported/thumbs/' + data.fileName}" width="75" height="75"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:Application>
====================================================
A DUMP OF THE DATAPROVIDER
in this case, one array item existed when launched, then a second was added
while running. The first has its thumbnail show, the second item has broken image
====================================================
------------------DUMP----------------------------
(mx.collections::ArrayCollection)#0
filterFunction = (null)
length = 2
list = (mx.data::DataList)#1
fillParameters = (Array)#2
length = 2
localItems = (Array)#3
[0] (com.stevenerat.news::NewsPhoto)#4
aperture = "F10"
cameraLens = "EF24-70mm f/2.8L USM"
cameraModel = "Canon EOS 7D"
city = ""
copyrightNotice = "© Steven Erat 2011"
country = ""
creator = "Steven Erat"
description = ""
dirPath = "/Users/stevenerat/LR_AUTO/imported/"
fileName = "ERAT_STEVEN_20110122_162.jpg"
focalLen = "42.0 mm"
headline = ""
id = 1
iso = "100"
keywords = "Alt, Dramatic, Fashion, Girl, Glamorous, Glamour, Inked, Model, Portrait, SOPHA"
psLock = "New"
shutterSpeed = "1/128 sec"
state = ""
[1] (com.stevenerat.news::NewsPhoto)#5
aperture = "F10"
cameraLens = "EF24-70mm f/2.8L USM"
cameraModel = "Canon EOS 7D"
city = ""
copyrightNotice = "© Steven Erat 2011"
country = ""
creator = "Steven Erat"
description = ""
dirPath = "/Users/stevenerat/LR_AUTO/imported/"
fileName = "ERAT_STEVEN_20110122_163.jpg"
focalLen = "42.0 mm"
headline = ""
id = 2
iso = "100"
keywords = "Alt, Dramatic, Fashion, Girl, Glamorous, Glamour, Inked, Model, Portrait, SOPHA"
psLock = "New"
shutterSpeed = "1/128 sec"
state = ""
uid = "8BAC025E-60D1-11F1-3654-44BDB0D218CE"
view = (mx.collections::ArrayCollection)#6
filterFunction = (null)
length = 2
list = (mx.data::DataList)#1
sort = (null)
source = (null)
sort = (null)
source = (null)
------------------END_DUMP------------------------I expected that if my extension uses the local filesystem AND the network that I would get a Security Sandbox Exception as I recently described in this thread:
http://forums.adobe.com/thread/791918?tstart=0
However, I just tried changing my datagrid image renderer to access the thumbnail via HTTP and the thumbnail issue after Lightroom export does not happen.
<mx:DataGridColumn headerText="Photo" dataField="fileName" width="80" editable="false">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="center" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:Image click="outerDocument.handlePhotoClick(data);" source="{'http://localhost:8500/LR_AUTO/imported/thumbs/' + data.fileName}" width="75" height="75"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
Furthermore, I can also open the image via the Photoshop DOM, and it does open correctly. It seems that I do have a solution now, although I'm not certain as to why I'm not getting a Security Sandbox Exception as I described in the other post.
Thanks for reading. -
DataGrid does not display XML data
Hello, and thanks for reading this...
I am having a problem displaying XMLList data in a DataGrid.
The data is coming from a Tree control, which is receiving it
from a database using HTTPService.
The data is a list of "Job Orders" from a MySQL database,
being formatted as XML by a PHP page.
If it would be helpful to see the actual XML, a sample is
here:
http://www.anaheimwib.com/_login/get_all_orders_test2.php
All is going well until I get to the DataGrid, which doesn't
display the data, although I know it is there as I can see it in
debug mode. I've checked the dataField property of the appropriate
DataGrid column, and it appears correct.
Following is a summary of the relevant code.
...An HTTPService named "get_all_job_orders" retrieves
records from a MySQL database via PHP...
...Results are formatted as E4X:
HTTPService resultFormat="e4x"
...An XMLListCollection's source property is set to the
returned E4X XML results:
...The "order" node is what is being used as the top-level of
the XML data.
<mx:XMLListCollection id="jobOrdersReviewXMLList"
source="{get_all_job_orders.lastResult.order}"/>
...The "jobOrdersReviewXMLList" collection is assigned to be
the dataProvider property of a Tree list, using the @name syntax to
display the nodes correctly, and a change event function is defined
to add the records to a DataGrid on a separate Component for
viewing the XML records:
<mx:Tree dataProvider="{jobOrdersReviewXMLList}"
labelField="@name"
change="jobPosForm.addTreePositionsToDG(event)"/>
...Here is the relevant "jobPosForm" code (the Job Positions
Form, a separate Component based on a Form) :
...A variable is declared:
[Bindable]
public var positionsArray:XMLList;
...The variable is initialized on CreationComplete event of
the Form:
positionsArray = new XMLList;
...The Tree's change event function is defined within the
"jobPosForm" Component.
...Clicking on a Tree node fires the Change event.
...This passes an event object to the function.
...This event object contains the XML from the selected Tree
node.
...The Tree node's XML data is passed into the positionsArray
XMLList.
...This array is the dataProvider for the DataGrid, as you
will see in the following block.
public function addTreePositionsToDG(event:Event):void{
this.positionsArray = selectedNode.positions.position;
...A datagrid has its dataProvider is bound to
positionsArray.
...(I will only show one column defined here for brevity.)
...This column has its dataField property set to "POS_TITLE",
a field in the returned XML record:
<mx:DataGrid width="100%" variableRowHeight="true"
height="75%" id="dgPositions"
dataProvider="{positionsArray}" editable="false">
<mx:columns>
<mx:DataGridColumn width="25" headerText="Position Title"
dataField="POS_TITLE"/>
</mx:columns>
</mx:DataGrid>
In debug mode, I can examine the datagrid's dataProvider
property, and see that the correct XML data from the Tree control
is present. However, The datagrid does not display the data in any
of its 6 columns.
Does anyone have any advice?
Thanks for your time.Hello again,
I came up with a method of populating the DataGrid from the
selected Item of a Tree Control which displays complex XML data and
XML attributes. After the user clicks on a Tree branch, I call this
function:
public function addTreePositionsToDG(event:Event):void{
//Retrieve all "position" nodes from tree.
//Loop thru each Position.
//Add Position data to the positionsArray Array Collection.
//The DataGrid dataprovider is bound to this array, and will
be updated.
positionsArray = new ArrayCollection();
var selectedNode:Object=event.target.selectedItem;//Contains
entire branch.
for each (var position:XML in
selectedNode.positions.position){
var posArray:Array = new Array();
posArray.PK_POSITIONID = position.@PK_POSITIONID;
posArray.FK_ORDERID = position.@FK_ORDERID;
posArray.POS_TITLE = position.@POS_TITLE;
posArray.NUM_YOUTH = position.@NUM_YOUTH;
posArray.AGE_1617 = position.@AGE_1617;
posArray.AGE_1821 = position.@AGE_1821;
posArray.HOURS_WK = position.@HOURS_WK;
posArray.WAGE_RANGE_FROM = position.@WAGE_RANGE_FROM;
posArray.WAGE_RANGE_TO = position.@WAGE_RANGE_TO;
posArray.JOB_DESCR = position.@JOB_DESCR;
posArray.DES_SKILLS = position.@DES_SKILLS;
positionsArray.addItem(posArray);
So, I just had to manually go through the selected Tree node,
copy each XML attribute into a simple Array, then ADD this Array to
an ArrayCollection being used as the DataProvider for the DataGrid.
It's not elegant, but it works and I don't have to use a Label
Function, which was getting way too complicated. I still think that
Flex should have an easier way of doing this. There probably is an
easier way, but the Flex documentation doesn't provide an easy path
to it.
I want to thank you, Tracy, for the all the help. I checked
out the examples you have at www.cflex.net and they are very
helpful. I bookmarked the site and will be using it as a resource
from now on. -
How can i access a mysql table without putting the data in a datagrid
I developed my air app with a datagrid which uses a php service to display all data from a table of strings in MySql.
I now do not need the datagrid, how can i get the data from my database without putting it into a dataGrid? Do i need an array? how do i do this? anyone got any example code?Balakrishnan V wrote:
var resultArrayCollection:ArrayCollection=new ArrayCollection()
protected function resultHandler(event:ResultEvent)
result=event.result as ArrayCollection
You can use the result array collection now inside your program for any further changes / manipulations.
Hope this helps; If you have further doubts, do ask...
Balakrishnan V
Hi, yeah this helps,
however, how would i generate a result handler for a service that has not been called yet? Sorry my knowledge of services is very limited.
This is a php service, get_all service that returns all the rows from a mysql table.
I can see the service box with the service i want to use:
but how do i pass that to a result handler? -
DataGrid not reflecting changes after INSERT into Table. Delete from Table does.
Wow, it's been a while.
Hope you guys can help.
This is my DataGrid:
<DataGrid DataContext="{StaticResource TableAssetsViewSource}" ItemsSource="{Binding}" x:Name="TableAssetsDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" Margin="15,10,10,10" RowDetailsVisibilityMode="VisibleWhenSelected" Grid.Column="1" HeadersVisibility="Column" CanUserResizeRows="False" IsReadOnly="True">
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="BorderThickness" Value="0"/>
</Style>
</DataGrid.CellStyle>
<DataGrid.Columns>
<DataGridTextColumn x:Name="NodeColumn" Binding="{Binding node}" Header="VS Number" Width="*"/>
<DataGridTextColumn x:Name="SerialColumn" Binding="{Binding serial}" Header="Serial Number" Width="*"/>
<DataGridTextColumn x:Name="NameColumn" Binding="{Binding name}" Header="Asset Name" Width="*"/>
<DataGridTextColumn x:Name="TypeColumn" Binding="{Binding type}" Header="Asset Type" Width="*"/>
<DataGridTextColumn x:Name="_dateColumn" Binding="{Binding date}" Header="Date Allocated" Width="*"/>
<DataGridTextColumn x:Name="PoColumn" Binding="{Binding po}" Header="Purchase Order" Width="*"/>
</DataGrid.Columns>
</DataGrid>
This is where I add a new Row to the Table:
Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs)
Dim cbblocation As ComboBox = Me.FindName("LocationComboBox")
Dim row As DataRowView = DirectCast(cbblocation.SelectedItem, DataRowView)
Dim cbbtext As String = row.Item("node")
Dim cbbtype As ComboBox = Me.FindName("comboBoxType")
Dim cbbtext2 As String = cbbtype.Text
Dim RETAILISOAMDDataSet As Retail_ISO_AMD.RETAILISOAMDDataSet = CType(Me.FindResource("RETAILISOAMDDataSet"), Retail_ISO_AMD.RETAILISOAMDDataSet)
Dim RETAILISOAMDDataSetTableAssetsTableAdapter As Retail_ISO_AMD.RETAILISOAMDDataSetTableAdapters.tableAssetsTableAdapter = New Retail_ISO_AMD.RETAILISOAMDDataSetTableAdapters.tableAssetsTableAdapter()
RETAILISOAMDDataSetTableAssetsTableAdapter.AddNewAsset(cbbtext, txbSerial.Text, txbName.Text, cbbtext2, Date.Today, txbPO.Text)
node = cbbtext
Dim mp As New MainPage
mp.RefreshGrid(node)
Me.Close()
End Sub
The RefreshGrid method:
Public Sub RefreshGrid(node As String)
Dim RETAILISOAMDDataSet As Retail_ISO_AMD.RETAILISOAMDDataSet = CType(Me.FindResource("RETAILISOAMDDataSet"), Retail_ISO_AMD.RETAILISOAMDDataSet)
Dim RETAILISOAMDDataSetTableAssetsTableAdapter As Retail_ISO_AMD.RETAILISOAMDDataSetTableAdapters.tableAssetsTableAdapter = New Retail_ISO_AMD.RETAILISOAMDDataSetTableAdapters.tableAssetsTableAdapter()
RETAILISOAMDDataSetTableAssetsTableAdapter.FillByNode(RETAILISOAMDDataSet.tableAssets, node)
Dim TableAssetsViewSource As System.Windows.Data.CollectionViewSource = CType(Me.FindResource("TableAssetsViewSource"), System.Windows.Data.CollectionViewSource)
Dim be As BindingExpression = BindingOperations.GetBindingExpression(TableAssetsViewSource, CollectionViewSource.SourceProperty)
be.UpdateTarget()
End Sub
And this is what I use to delete a row from the table (and without doing anything special, the DataGrid auto-updates with the changes):
Private Sub Button_Click_4(sender As Object, e As RoutedEventArgs)
If TableAssetsDataGrid.SelectedIndex = -1 Then
MsgBox("You have selected nothing to Delete!", MsgBoxStyle.OkOnly, "Nothing Selected")
Else
Dim dgv As DataGridTextColumn = Me.FindName("NodeColumn")
Dim row As DataRowView = DirectCast(Me.TableAssetsDataGrid.SelectedItem, DataRowView)
Dim dgvText As String = row.Item("node")
Dim dgv2 As DataGridTextColumn = Me.FindName("SerialColumn")
Dim row2 As DataRowView = DirectCast(Me.TableAssetsDataGrid.SelectedItem, DataRowView)
Dim dgvText2 As String = row.Item("serial")
Dim dgv3 As DataGridTextColumn = Me.FindName("NameColumn")
Dim row3 As DataRowView = DirectCast(Me.TableAssetsDataGrid.SelectedItem, DataRowView)
Dim dgvText3 As String = row.Item("name")
Dim dgv4 As DataGridTextColumn = Me.FindName("TypeColumn")
Dim row4 As DataRowView = DirectCast(Me.TableAssetsDataGrid.SelectedItem, DataRowView)
Dim dgvText4 As String = row.Item("type")
Dim dgv5 As DataGridTextColumn = Me.FindName("_dateColumn")
Dim row5 As DataRowView = DirectCast(Me.TableAssetsDataGrid.SelectedItem, DataRowView)
Dim dgvText5 As String = row.Item("date")
Dim dgv6 As DataGridTextColumn = Me.FindName("POColumn")
Dim row6 As DataRowView = DirectCast(Me.TableAssetsDataGrid.SelectedItem, DataRowView)
Dim dgvText6 As String = row.Item("po")
Dim RETAILISOAMDDataSet As Retail_ISO_AMD.RETAILISOAMDDataSet = CType(Me.FindResource("RETAILISOAMDDataSet"), Retail_ISO_AMD.RETAILISOAMDDataSet)
Dim RETAILISOAMDDataSetTableAssetsTableAdapter As Retail_ISO_AMD.RETAILISOAMDDataSetTableAdapters.tableAssetsTableAdapter = New Retail_ISO_AMD.RETAILISOAMDDataSetTableAdapters.tableAssetsTableAdapter()
RETAILISOAMDDataSetTableAssetsTableAdapter.RemoveAsset(dgvText, dgvText2, dgvText3, dgvText4, dgvText5, dgvText6)
Dim cbb As ComboBox = Me.FindName("cbbLocation")
Dim row7 As DataRowView = DirectCast(cbb.SelectedItem, DataRowView)
Dim cbbtext As String = row.Item("node")
RefreshGrid(cbbtext)
End If
End Sub
--------- End of Edit
It is bound to a Dataset which gets it's data from a SQL Database.
Loading the Data and Filtering the data based on certain conditions work 100%. The problem I am having is as follows:
I have a form on the Page that takes input and inserts a row into the Database. When this happens, the DataGrid won't automatically reflect the changes (even if I recall the Fill Method of the Dataset). No matter what I do, I have to refresh the entire page
and THEN Fill the Dataset to see any changes.
This is what strikes me as odd...
When I do a delete row operation on the Database (Custom Method on the Dataset with conditions), and just Fill the Dataset again (without doing anything special), the row deletes and the changes is reflected IMMEDIATELY.
What am I doing wrong here? Why would Delete Row reflect the changes on the DataGrid but no Insert Row?
Thanks in Advance.
(P.S. I am very rusty with my developing skills, I haven't done this in YEARS)>>And what about the the most important question, how exactly is TableAssetsViewSource defined in the XAML markup and what is
its Source property set or bound to? And what about the reproducable sample...?
Here is the Markup of the TableAssetsViewSource:
<Page.Resources>
<local:RETAILISOAMDDataSet x:Key="RETAILISOAMDDataSet"/>
<CollectionViewSource x:Key="TableRegionsViewSource" Source="{Binding tableRegions, Source={StaticResource RETAILISOAMDDataSet}}"/>
<CollectionViewSource x:Key="TableLocationsViewSource" Source="{Binding tableLocations, Source={StaticResource RETAILISOAMDDataSet}}"/>
<CollectionViewSource x:Key="TableAssetsViewSource" Source="{Binding tableAssets, Source={StaticResource RETAILISOAMDDataSet}}"/>
</Page.Resources>
The ItemsSource of the DataGrid is bound to the TableAssetsViewSource:
<DataGrid DataContext="{StaticResource TableAssetsViewSource}" ItemsSource="{Binding}" x:Name="TableAssetsDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" Margin="15,10,10,10" RowDetailsVisibilityMode="VisibleWhenSelected" Grid.Column="1" HeadersVisibility="Column" CanUserResizeRows="False" IsReadOnly="True">
Just remember, this code was auto-generated with the drag & drop onto the Page, so I did little in terms of setting the actual bindings.
All in all, what I have done so far works as intended, except that when I want to add a row to the table it does not reflect, and that it only shows after refreshing/restarting the application.
I will try and put together a reproducable sample. -
How do I set only the first row of a DataGrid as the selected row?
I have a "Go" button on a search form that fetches data into an already data bound grid. After the data is fetched, I want to make the first row in the Datagrid the selected row, as if the user clicked on it. If the result set is empty, I don't want the code to crash. (I only want one row to be able to be selected at a time)
protected function btnGo_clickHandler(event:MouseEvent):void
getSBJsResult.token = baa_data_svc.getSBJs(cmbSrch.text);
grdSBJs. // ????? What goes here to select the first row?This should do it.
If this post answered your question or helped, please mark it as such.
if(myDataGrid.dataProvider.length > 0){
myDataGrid.selectedIndex = 0; -
DataGrid ItemRender and font family
i am writing a custom data grid ItemRender that, for every
cell, displays a numeric value. Additionally, if the xml data
structure defines an attribute for a given row, it is supposed to
display a colored arrow in the same cell.
Reading the data and determining if to display the arrow, and
the color of the arrow work fine. I am trying to embed the
windgings font to display the arrow, that way I can set the color
programatically. As I said, reading the data works fine, the
coloring of the 'arrow' works fine. My problem is I cannot change
the fontFamily of any label in the item renderer. Even the entire
renderer itself. Below is my code, followed by several other things
I have tried. Thanks for the help.
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="
http://www.adobe.com/2006/mxml"
width="100%" height="100%"
implements="mx.controls.listClasses.IDropInListItemRenderer"
horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:Style>
@font-face
src: local("wingdings");
fontFamily: myArrowFont;
font-anti-alias-type: advanced;
font-weight: bold;
.arrowStyle
fontFamily: myArrowFont;
font-weight: bold;
font-size: 12;
</mx:Style>
<mx:Script>
<![CDATA[
import mx.controls.listClasses.BaseListData;
import mx.controls.dataGridClasses.DataGridListData;
protected var _listData:DataGridListData;
public function get listData():BaseListData
return _listData;
public function set listData(value:BaseListData):void
_listData = DataGridListData(value);
invalidateProperties();
override public function set data(value:Object):void
super.data = value;
cellArrow.setStyle('color',value[_listData.dataField].@color);
switch(value[_listData.dataField][email protected]())
case 'up':
cellArrow.text = 'é';
break;
case 'down':
cellArrow.text = 'ê';
break;
case 'equal':
cellArrow.text = 'd';
break;
default:
cellArrow.text = '';
break;
cellText.text = value[_listData.dataField];
]]>
</mx:Script>
<mx:Label id="cellText" text=""/>
<mx:Spacer width="100%"/>
<mx:Label id="cellArrow" styleName="arrowStyle"
text=""/>
</mx:HBox>
I have tried using <mx:Label id="cellArrow"
fontFamily='myArrowFont'/>
I have set the fontFamily='myArrowFont' in the base HBox tag
as well, and it doesn't change the font of either the cellArrow or
cellText label.
I have also used
cellArrow.setStyle('fontFamily','myArrowFont') in the override set
data method.
I have written the same component in ActionScript
implementing the same functionality.
The cellArrow label's text and color are set correctly to the
data, however I cannot get the font to change to windgings.
I have tried setting the DataGridColumn fontFamily to the
wingdings font, and all it does is change the header text of the
column, not any of the rows.
The actual datagrid is created entirely in actionscript,
because it is part of a control that will build a datagrid with X
number of columns, defined in a data structure. That code works
fine as well, and is below, incase it helps.
//_dataP is an XMLList from an httpservice or web service
that defines our grids
var colsX:XMLList = _dataP..column; //get an xmllist of our
columns
var len:int = colsX.length(); //and store the length
var cols:Array = new Array(); //create an empty array to hold
each column
var col:DataGridColumn; //a data grid column reference
for(var i:int = 0; i < len; i++)
col = new DataGridColumn(); //create a new column
col.headerText = colsX
.@text; //set the header text
col.dataField = colsX.@field; //and data field
col.itemRenderer = new ClassFactory(quadBoxItemRenderer);
cols.push(col); //add it to the array
_grid.columns = cols; //set our columns array as the columns
of the grid
var rows:XMLList = _dataP..row;
_grid.rowCount = (rows.length() == 0) ? 1 : rows.length();
_grid.dataProvider = rows; //and give it the list of rows
_grid.percentWidth = 100;
_gridBox.addChild(_grid);
any help is vastly appreciated. Thanks.Disregard my question - I've unfortunately failed to check the font-family string as submitted by the server and it turned out to still have a colon character in front of it...
I guess I've spent a few too many nights working on this making me susceptible to tiredness and a strangely blank mind...
My apologies,
Rogier -
Special characters into datagrid through the use of buttons
Hi!
I have a datagrid for word input, I'm trying to create a "special characters" panel, kind of like google's new "virtual keyboard" thing on google.com, so that the user can enter data into the datagrid cells using characters that aren't on their keyboards.
I manage to do this just fine, using the solution below. I know this is probably not the best/most effective way to do this, so any suggestions for making the code better will be appreciated. I only started using Flex a month ago.
grid.addEventListener(DataGridEvent.ITEM_EDIT_BEGIN, selectColumn)
function selectColumn(event:DataGridEvent):void
var selectedColumn:DataGridColumn = grid.columns[event.columnIndex];
selCol = selectedColumn.dataField;
//The function for adding a special character to the selected datagrid column by clicking a button:
//(inputWordArray is the dataprovider for the grid called "grid" )
protected function clickSomeButton(event:MouseEvent):void
var colIndex:int = new int;
if (selCol == "from"){
inputWordArray[grid.selectedIndex].from = inputWordArray[grid.selectedIndex].from + "æ";
colIndex = 0;
else if (selCol == "to"){
colIndex = 1;
inputWordArray[grid.selectedIndex].to = inputWordArray[grid.selectedIndex].to + "æ";
inputWordArray.refresh();
grid.dispatchEvent(new DataGridEvent(DataGridEvent.ITEM_EDIT_BEGINNING, false, false, colIndex, null, grid.selectedIndex));
The problem is that this only adds a letter at the end of the selected item's value, not at a specific position within the word specified by the position of the cursor. This is what I need to achieve. I have no idea even what to search for, if anyone could please give me a hint that'd be great.You will probably need to capture the editor's selectionBeginIndex and
selectionEndIndex -
Flash 2.0 Datagrid component bug ?
Recently I found a bug in Datagrid component. The swf file
which contain datagrid act differely in IE 6, and IE 7.
This is what I've done:
1) Compile swf, export it together with html file.
2) Run the html file
3)Press on one of the cell,drag it and then release it
outside of the browser/flash canvas.
4)Move the mouse pointer back to flash canvas
5)The grid will scroll automatically( move the move up and
down to test)
6)After a few times mouse pointer movement, suddenly IE
crash, CPU usage 100%
I have tested the swf file on firefox 2.007 and stand alone
flash player, however, none of the flash player have this bug.
Therefore I suspect that the ActiveX flash plugin for IE cause this
bug.
This is the source code, which I use to create the datagrid
for testing.
ps: open one fla file, drag datagrid component from component
panel to the stage or it will not run.
import mx.controls.DataGrid;
var header = "Stock Code/\nName,Type,Status,Order
Date\nTime,Duration,OrderQty/\nPrice,Matched Qty/\nPrice,Trd
Curr/\nMatched Value,Account No/\nOrder No";
var wid =
"90,43.2699356842522,91.5969497381748,87.4747020181826,60.4473499934867,67.9851014914014, 90.2231829093762,111.8984058876167,134.104372277509";
var alig = "left ,left, left , left , left , right , right ,
right , left ";
var halig = "center ,center,center , center , center , center
, center , center , center ";
var fxdata:Array = new Array();
fxdata[0]= new Array("67676
GPACKET","Buy","Expired","05/09/2007 06:04:20 PM","Day","200
4.34","0 0.00","MYR 0.00","423423423432");
fxdata[1]= new Array("054066
FASTRAK","Buy","Expired","05/09/2007 01:45:18 PM","Day","47,900
0.27","0 0.00","MYR 0.00","fdsfsdfsdf");
fxdata[2]= new Array("737013
HUBLINE","Sell","Expired","05/09/2007 11:53:19 AM","Day","400
0.69","0 0.00","MYR 0.00","93743");
fxdata[3]= new Array("31474
L&G","Buy","Expired","03/09/2007 11:35:35 AM","Day","500
0.70","0 0.00","MYR 0.00","389dskjfsd");
fxdata[4]= new Array("38182
GENTING","Buy","Expired","28/08/2007 11:38:59 AM","Day","500
7.35","0 0.00","MYR 0.00","90sklsdakl");
fxdata[5]= new Array("05005
PALETTE","Buy","Expired","28/08/2007 11:08:23 AM","Day","500
0.115","0 0.00","MYR 0.00","jsdaflk;as");
fxdata[6]= new Array("093082
GPACKET","Buy","Expired","27/08/2007 03:49:43 PM","Day","300
3.82","0 0.00","MYR 0.00","jsdafj;sda");
fxdata[7]= new Array("644769
KELADI","Buy","Expired","27/08/2007 11:05:36 AM","Day","10,000
0.30","0 0.00","MYR 0.00","jsadjf;lkdas");
fxdata[8]= new Array("676653
KASSETS","Buy","Expired","24/08/2007 06:15:33 PM","Day","500
2.93","0 0.00","MYR 0.00","jlsdf;adas");
fxdata[9]= new Array("473323
JAKS","Buy","Expired","23/08/2007 04:45:03 PM","Day","100 0.915","0
0.00","MYR 0.00","jjkljsdlfasd");
fxdata[10]= new Array("03069
IPOWER","Buy","Expired","22/08/2007 10:18:01 AM","Day","9,800
0.365","0 0.00","MYR 0.00","jlajsd;lfjads");
fxdata[11]= new Array("05025
LNGRES","Buy","Expired","21/08/2007 03:08:06 PM","Day","9,900
0.28","0 0.00","MYR 0.00","jlkjsdafl");
fxdata[12]= new Array("01308 N2N","Buy","Expired","21/08/2007
10:34:51 AM","Day","200 1.71","0 0.00","MYR 0.00","mjkjadsflasd");
fxdata[13]= new Array("70069
IPOWER","Buy","Cancelled","21/08/2007 10:02:08 AM","Day","0
0.37","0 0.00","MYR 0.00","jkjasd;fsda");
fxdata[14]= new Array("03069
IPOWER","Buy","Cancelled","20/08/2007 07:20:54 PM","Day","0
0.38","0 0.00","MYR 0.00","jkjsdlkfjsdaf");
fxdata[15]= new Array("12651
MRCB","Buy","Replaced","20/08/2007 05:31:59 PM","Day","900 2.35","0
0.00","MYR 0.00","upuewoirwe");
var mdtgrid:DataGrid;
_root.createEmptyMovieClip("displayobj1",
_root.getNextHighestDepth(),{_x:0,_y:0});
initial();
function initial(){
_root.mdtgrid =
_root.createClassObject(mx.controls.DataGrid, "xxx",
_root.getNextHighestDepth());
_root.mdtgrid.doLater(_root,"setData");
function setData(){ //insert data to datagrid
var temp:Array = new Array();
for (var i in _root.fxdata){
temp
= new Object();
for (var j in _root.fxdata){
temp
[j] = _root.fxdata[j];
_root.mdtgrid.dataProvider =temp;
_root.mdtgrid.doLater(_root,"setdgStyle");
function setdgStyle(){
var rowhight = 40;
var noofrow = 8;
var headerheight = 35;
var gridheight = (rowhight * noofrow) + headerheight ;
_root.mdtgrid.setSize(800, gridheight);
_root.mdtgrid.rowHeight =rowhight;
_root.setHeader(_root.header.split(","));
_root.setWidth(_root.wid.split(","));
_root.setAlign(_root.alig.split(","));
_root.mdtgrid.invalidate();
function setHeader(datasource:Array){ //set header label
var leng:Number = _root.mdtgrid.columnCount;
var sleng:Number = datasource.length;
var temp:Object;
for (i =0 ;i<leng;i++){
if (i>=sleng){
break;
_root.mdtgrid.getColumnAt(i).headerText = datasource
function setWidth(datasource:Array){ //set columns width
var leng:Number = _root.mdtgrid.columnCount;
var sleng:Number = datasource.length;
var temp:Object;
for (i =0 ;i<leng;i++){
if (i>=sleng){
break;
_root.mdtgrid.getColumnAt(i).width = Number(datasource);
function setAlign(datasource:Array){ //set Alignment
var leng:Number = _root.mdtgrid.columnCount;
var sleng:Number = datasource.length;
var temp:Object;
for (i =0 ;i<leng;i++){
if (i>=sleng){
break;
temp = _root.mdtgrid.getColumnAt(i);
temp.setStyle("textAlign",trim(datasourceAnyone know how to fix it ?
-
Urgent help required to make variableRowHeight & rowCount work hand in hand for a Datagrid
HI,
I am using variableRowHeight property on a datagrid to wrap the text and this works perfectly.
At the same time, I have to assign rowCount dynamically. My logic for caluculating rowCount is rowcount = sampleData.length > 5 ? 5:sampleData.length; where sampleData is my ArrayCollection. The caluculation happens correctly.
The issue here is rows of the datagrid do not show correctly.
From the post http://forums.adobe.com/message/2350643#2350643 I understood that both variableRowHeight & rowCount do not work hand in hand.
So, I tried removing variableRowHeight and it works fine. The solution says using measureHeightOfItems and viewMetrics to calculate the height may solve the issue. I did not understand it very clearly.
Can anyone let me know the solution with example.
Thnaks
Code
=========
<?xml version="1.0"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()" xmlns:itemren="
com.itemren.*">
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import com.vo.HeaderVO;
import com.vo.DataVO;
import mx.utils.ObjectUtil;
import mx.collections.IViewCursor;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
Bindable]
public static var sampleData:ArrayCollection = new ArrayCollection ();
Bindable]
public var rowcount:int;
public function init():void {
sampleData.addItem( { AssetNo :
"234567890", AssetName : "Asset Name 1", Amount : "10000.02" } );sampleData.addItem( { AssetNo :
"234567891", AssetName : "Asset Name 2", Amount :"2.04" } );sampleData.addItem( { AssetNo :
"234567892", AssetName : "Asset Name 3", Amount : "4578.00" } );sampleData.addItem( { AssetNo :
"234567893", AssetName : "Asset Name 4", Amount : "384.00" } );sampleData.addItem( { AssetNo :
"234567894", AssetName : "Asset Name 5", Amount : "21454.20" } );sampleData.addItem( { AssetNo :
"234567890", AssetName : "Asset Name 1", Amount : "10000.02" } );sampleData.addItem( { AssetNo :
"234567891", AssetName : "Asset Name 2", Amount :"2.04" } );sampleData.addItem( { AssetNo :
"234567892", AssetName : "Asset Name 3", Amount : "4578.00" } );
trace ("sampleData.length ========= "+sampleData.length);
rowcount = sampleData.length > 5 ? 5:sampleData.length;
trace("count is ==== "+rowcount);
dg.rowCount=rowcount;
trace("dg.rowCount is === "+ObjectUtil.toString(dg.rowCount));
dg.dataProvider=sampleData;
]]>
</mx:Script>
<mx:Panel title="POC for dynamic rowCount of datagrid" height="100%" width="100%" paddingTop="
10" paddingLeft="10" paddingRight="10">
<mx:DataGrid id="dg" width="50%" wordWrap="true" variableRowHeight="
true">
<mx:columns>
<mx:DataGridColumn dataField="AssetNo" headerText="Asset No" paddingLeft="20" />
<mx:DataGridColumn dataField="AssetName" headerText="Asset Name" paddingLeft="20"/>
<mx:DataGridColumn dataField="Amount" headerText="Amount" paddingLeft="20"/>
</mx:columns>
</mx:DataGrid>
</mx:Panel>
</mx:Application>Hi,
have you checked your bindings not only for the WF --> Method, also for the Method --> WF?
Christoph
Of course I mean the bindings between Task and Method / Method and Task
Edited by: Christoph Schle on Dec 21, 2007 11:05 AM -
How do I reference the data object in a DataGrid to show an image correctly in Acrobat?
I'm creating an inferface for an Acrobat application and I'm having a issue with displaying an image in a grid. When I hard code the source="statusNONE.png" it works as intended (with an image, not the image associated with each grid item), however, when I try to use the source="{data.@icon}" to reference the dataProvider (XMLListCollection) I get nothing. Not a broken image or anything. I think I may just not be referencing the XMLListCollection correctly, otherwise I don't know why it would work with hard coding vs. fetching the string from the XML.
//Application Header (Flex 4.5)
<?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"
width="100%" height="100%" creationComplete="eaton_creationCompleteHandler(event)"
currentState="Review">
//Sample of XML that gets used as basis for XMLListCollection
<Annots>
<Annot name='TEST' index='14' feedback='' canConstruct='0' icon='statusNONE.png'/>
</Annots>
//creation of the XMLListCollection from String
[Bindable] protected var fullXML:XML;
[Bindable] protected var fullXMLCol:XMLListCollection;
protected function loadXML(xmlString:String):void
fullXML = new XML(xmlString);
var fullXMLList:XMLList = fullXML.children();
fullXMLCol = new XMLListCollection(fullXMLList);
//DataGrid
<s:DataGrid left="0" top="0" bottom="0" width="142" dataProvider="{fullXMLCol}"
requestedRowCount="4" rowHeight="30"
top.Confirm="87">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="@name" headerText="Annotations"></s:GridColumn>
<s:GridColumn headerText="status" width="30" >
<s:itemRenderer>
<fx:Component>
<s:GridItemRenderer>
<s:Image width="30" height="30" source="{data.@icon}"/> //THIS IS THE PART THAT SEEMS TO BE GIVNG ME TROUBLE!
</s:GridItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:GridColumn>
</s:ArrayList>
</s:columns>
<s:typicalItem>
<fx:Object dataField1="Sample Data" dataField2="Sample Data" dataField3="Sample Data"></fx:Object>
</s:typicalItem>
</s:DataGrid>
Additional information. I'm using the resources tab for the flash embedding in Acrobat for my images. This works when I am hard coding the file name string works for the source without having to add a full path, the images are not technically bundled into the swf. I just don't understand why using the data object to get that same string would show different results.
tl;dr: GridItemRenderer works to show images when hard coded but not when using {data}.
UPDATE: Figured it out, needed to add a toString() to the data.@icon. I had assumed it was a string being handed over, I assumed wrong.Probably because data.@icon isn't a String, it is an XMLList, and source property is an Object not a String so the runtime doesn't automatically convert it.
Try [email protected]() -
Datagrid rearranging columns?
I'm having a problem. This code i have written will import
the XML but it rearranges the fields when i do this:
"for (var subKey:String in data[0])"
All of the fields come through but the subKey order is not in
the order of the actual XML. Is there any way to get the
"$ColumnNames[$w]" var from php over to flex in the same order?
I don't know if i just reinvented the wheel, but it was
definitely a good learning experience.
MXML is first then PHP is second. Some of the code is copied
off other examples. I didn't see any copyrights but let me know if
there are any problems. O and the error thing doesn't work on the
PHP page.I am look for a solution to a similar problem.
I've got this nice little .fla that displays a DataGrid component (Flash CS3 Professional) using a DataProvider created from XML loaded from URLRequest/URLLoader (.asp source, but could be PHP, etc.).
It works great except for one little annoying item. The order of the columns seems to be totally arbitrary.
I was expecting the order of the column to be the same as they occur in the XML DATA element.
Here is a sample DATA element (there are serveral such DATA elements in the XML:
<DATA>
<AreaID>TNV</AreaID>
<AreaName>TN, VA</AreaName>
<MaxDvrHT>4</MaxDvrHT>
<BoardName>TN, VA</BoardName>
<RegionName>SOUTHEAST</RegionName>
<salesGroup>David</salesGroup>
</DATA>
Here is the function that builds DataGrid:
function returnAJAXcallback(evtObj:Event):void{
// executed by URLLoader event listener "complete"
// load the XML returned from .asp into XML object
var myXML:XML = XML(evtObj.target.data);
// create a data provider from the XML
var myDP = new DataProvider(myXML);
// create a DataGrid
var myDataGrid:DataGrid = new DataGrid;
// set the data provider
myDataGrid.dataProvider=myDP;
myDataGrid.width = 900;
myDataGrid.height = 500;
// show DataGrid on stage
addChild(myDataGrid);
for each (var child:XML in myXML.DATA) {
trace(child) ; // list each DATA segment
Here is the order that the columns appear in the DataGrid (left to right):
AreaName
RegionName
salesGroup
AreaID
MaxDvrHT
BoardName
So, how in the world does Flash come up with this order?
Why not default to the order in which the columns appear in the XML?
Now, if some nice person knows the answer (I'm pretty new to Flash), what do I need to do (with as little code as possible) to get the columns ordered in a similar fashion to the order in which the XML data elements appear?
Thanks to all. -
Adding new data row(s) to DataGrid control
My requirement is to provide the ability to add a new row to
the datagrid when tabbed out of the (last cell of the last row of
the datagrid. I have made my datagrid editable and in the
'itemEditEnd' handler I am adding a new object (with empty values)
to the data provider for the Grid and setting focus to the Grid and
then setting the new row index as the Selected Index for the Grid.
None of this activating itemEditor for the first cell of the new
row.
I have seen somewhere that dispatching the itemEditBeginning
will do this for me. But not sure how to do this. Appreciate if can
point me to a sample woring example.Perfect - Have been looking for a solution since few days.
You just made my day. Thank you so much. -
Getting values from a datagrid to an ArrayCollection
Hi, I have a drag and dropable datagrid. I fill it with rows of data from another datagrid. Finally, my application demands savings the data from the datagrid into an array collection along with the index of each row. How do i get values from a datagrid into an arrayCollection variable? Please help me..!
Whatever is dropped into the DataGrid automatically goes into its dataProvider property, typically an ArrayCollection. Just access the data grid's dataProvider property to see the values.
Maybe you are looking for
-
Hello BI Guru's I have standard 3.x data source which is using currently in production system. As per new requirement i have enhanced the data source with new fieldas and existing data source using most of the fields,but for my requirement i need at
-
How do I Delete an iTunes U Site?
Does anyone know how to delete an iTunes U Site? We are looking to create a new account.
-
URL is not change after successful authenticate with ISE 1.1.1
Hi, I have setup Cisco Identity Service Engine (1.1.1) with Wireless LAN Controller (7.2.110) Everything is complete unless the URL redirect. My guest client can join the Guest SSID and also can authenticate to ISE. But after they success to authenti
-
Time and date function, how to use?
Hello everyone, I want to know that how can we make use of these two system functions SY-TIMLO, SY-DATUM ? What should i write in data? pbo? pai? Should i write something like this in data? DATA: Ok_date TYPE SY-DATUM. DATA: Ok_time TYPE SY-TIMLO. Wh
-
Hi; How to retreive the content of a external JSP located in : C:/jsp/F1.jsp in another JSP located in the Webapp directory: ../WEB-INF/webapps/jsp/F2.jsp ? Regards;