0

Using the following SQLite statement:

SELECT Customer, SUM(OrderAmount) AS TotalOrder FROM OrdersTable GROUP BY Customer

I get the result of total sum (total order) of each customer

How can I put the above result into a itemRenderer label.text ?

<s:ItemRenderer>
   <s:Label id="customerName" text=??? />
   <s:Label id="totalOrder" text=??? />
</s:ItemRenderer>

thanks

jameslcs
  • 265
  • 2
  • 8
  • 25

2 Answers2

2

Whenever we set data to a dataprovider it automatically set to its item renderer, if you are using custom itemrendere then do this...

[Bindable] private var _customerName:String;
[Bindable] private var _totalOrder:String;

override public function set data(value:Object):void{
  this.data = value;
  _customerName = value. property   //propertyName containing customer name
  _totalOrder = value. property   //propertyName containing totalOrder
}

   <s:Label id="customerName" text="{_customerName}" /> 
   <s:Label id="totalOrder" text="{_totalOrder}" /> 

or

<s:ItemRenderer>    
   <s:Label id="customerName" text="{data.properyNamecontainCustomerName}" />    
   <s:Label id="totalOrder" text="={data.properyNamecontaintotalOrder} " />    
</s:ItemRenderer> 
ashoo_bob
  • 162
  • 3
  • 1
    missed it... by that much :) Good answer! – Sunil D. Apr 12 '12 at 06:15
  • 1
    Never do bindings within ItemRenderers. It is considered as being bad practice. It can cause performance issues and in the worst case, memory leaks. Therefore you should always override the `set data` function. – Dennis Jaamann Apr 12 '12 at 07:10
  • @DennisJaamann interesting, i don't know that using binding within IR is a bad practice as a lot of books/websites use it. nice to know. – jameslcs Apr 12 '12 at 14:56
0

ItemRenderer's have a data property which the Flex List control sets on each renderer. You can bind the text property of a Label to the data, override the setter for the data property, or add an event listener for the "dataChange" event.

When binding you can use curly brace expressions like this:

<s:Label text="{data.customerName}" />

This assumes that the data provider for your List is populated w/an object that has the property customerName ;)

The other two approaches require that you write some code that sets the label's text property.

You can find many examples of using a Flex ItemRenderer, such as these:

Sunil D.
  • 17,983
  • 6
  • 53
  • 65