Flex 4 中 Datagrid 行的格式不同
我在数据网格的一列中使用以下 itemrenderer。但是我想以不同的方式格式化数据网格的每一行。该列由数字组成,但有些需要格式化为数字,而另一些则需要格式化为货币等。另请注意,我还有一个由 0 和 1 组成的附加列,其中 0 表示它应该格式化为数字,1 表示它应该是格式为货币。
<?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" top="0" left="0" textAlign="center" verticalAlign="middle" right="0" bottom="0" text="{dataGridListData.label}" backgroundColor="#EDFB09"/>
<s:Rect left="0" right="0" top="0" bottom="0">
<s:stroke>
<s:SolidColorStroke color="0x000000" weight="1"/>
</s:stroke>
</s:Rect>
<fx:Script>
<![CDATA[
]]>
</fx:Script>
</s:MXDataGridItemRenderer>
关于如何实现这样的函数的任何帮助,我尝试在 itemrenderer 的函数中使用 dataGridListData.label 但它给出错误。
帮助谢谢
I am using the following itemrenderer in one of the column of my datagrid. However I want to format each row of the datagrid differently. The column consists of numbers but some need to be formatted as Numbers while others as currency etc. Also note that I have an additional column which consists of 0 and 1 where 0 means that it should be formatted as Number and 1 means that it should be formatted as Currency.
<?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" top="0" left="0" textAlign="center" verticalAlign="middle" right="0" bottom="0" text="{dataGridListData.label}" backgroundColor="#EDFB09"/>
<s:Rect left="0" right="0" top="0" bottom="0">
<s:stroke>
<s:SolidColorStroke color="0x000000" weight="1"/>
</s:stroke>
</s:Rect>
<fx:Script>
<![CDATA[
]]>
</fx:Script>
</s:MXDataGridItemRenderer>
Any help upon how I can implement such a function, am trying to use dataGridListData.label in a function in the itemrenderer but it gives error.
Help Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么 dataGridListData 对象应该已经包含您需要的所有信息:
列索引、行索引、数据字段。
在简单的情况下,使用“elvis-operator”(?作为 if 语句的简写)非常方便:
(condition) ? true-block: else-block
一些示例:
color="{(dataGridListData.rowIndex % 2 == 0) ? #00ff00 : #0000ff}" (用于交替行颜色)
text="{(dataGridListData.dataField == "coolField") ? '酷!': '不酷'}"
Well the dataGridListData object should allready contain all information you need:
columnIndex, rowIndex, dataField.
In simple cases, the usage of the "elvis-operator" (? as shorthand of an if-statement) comes in really handy:
(condition) ? true-block: else-block
Some examples:
color="{(dataGridListData.rowIndex % 2 == 0) ? #00ff00 : #0000ff}" (For alternating row colors)
text="{(dataGridListData.dataField == "coolField") ? 'Coool!': 'Uncool'}"
可以通过实现 IDataRenderer、IDropInListItemRenderer 创建自定义渲染器。
这允许访问 _listdata 和 _data。列表数据代表行。在setData中我们可以访问行
//取决于列,它可以被适当地格式化
Custom renderer can be created by implementing IDataRenderer, IDropInListItemRenderer.
This gives access to _listdata and _data. List data represents row. in setData we can access the row as
//depending on column, it can be appropriately formatted