actionscript 3 - Flex Datagrid labelFunction query -


main.mxl

<s:datagrid dataprovider="{employeedata}"> // employeedata arraycollection predefined data           <s:typicalitem>             <s:dataitem firstname="christopher"                          lastname="winchester"                          hiredate="22/12/2013"/>         </s:typicalitem>           <s:columns>              <s:arraylist>                  <s:gridcolumn labelfunction="employeename"                               headertext="name"/>                  <s:gridcolumn datafield="hiredate"                               headertext="hire date"                               labelfunction="dateformat"/>             </s:arraylist>          </s:columns>       </s:datagrid>      <fx:script>         <![cdata[             import mx.collections.arraycollection;             import mx.controls.datagridclasses.datagridcolumn;             import mx.rpc.events.resultevent;              [bindable]             private var employeedata: arraycollection;                private function employeename(item: object, column: gridcolumn): string             {                 return item.firstname+" "+item.lastname;             }           ]]>     </fx:script> 

a) can please explain me how datagrid internally works employeename function? mean, iam not passing 2 parameters labelfunction, still how called?

b) why should use s:arraylist tag inside s:columns tag?

a) can please explain me how datagrid internally works employeename function? mean, iam not passing 2 parameters labelfunction, still how called?

the labelfunction property on gridcolumn class. inside gridcolumn there itemtostring() function used determine label should specific instance of column. right out of framework code:

/**  *  @private  *  common logic itemtolabel(), itemtodatatip().   logically code  *  similar (not same as) labelutil.itemtolabel().  */ private function itemtostring(item:object, labelpath:array, labelfunction:function, formatter:iformatter):string {     if (!item)         return error_text;      if (labelfunction != null)         return labelfunction(item, this);      var itemstring:string = null;     try      {         var itemdata:object = item;         each (var pathelement:string in labelpath)             itemdata = itemdata[pathelement];          if ((itemdata != null) && (labelpath.length > 0))             itemstring = (formatter) ? formatter.format(itemdata) : itemdata.tostring();     }     catch(ignored:error)     {     }              return (itemstring != null) ? itemstring : error_text; } 

b) why should use s:arraylist tag inside s:columns tag?

because data type of columns property on datagrid ilist; , arraylist implements ilist interface. you're looking @ mxml way create , define arraylist. you'd use different approach if wanted create columns in actionscript.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -