2 Replies Latest reply on Nov 14, 2009 5:47 AM by Alexander2002

    Flex 3 Datagrid combine dataField

    Alexander2002

      My Datagrid code is :

       

                 <mx:DataGrid id="dtgUsers" doubleClickEnabled="true">
                      <mx:columns>
                         
                          <mx:DataGridColumn headerText="User Id" dataField="userId"/>
                          <mx:DataGridColumn headerText="Name" dataField="firstName"/>


                      </mx:columns>
                  </mx:DataGrid>

       

       

      My XML for dataProvider is :

       

      <Root>

      <User>
           <key>1026</key>
           <firstName>ADM</firstName>
           <lastName>USER</lastName>
           <loginAttemptsAllowed>0</loginAttemptsAllowed>
           <effectiveDate>2009-04-22 00:00:00.0</effectiveDate>
           <expiryDate>2010-04-22 00:00:00.0</expiryDate>         

      </User>
      <User>
           <key>1041</key>
           <firstName>Alex</firstName>
           <lastName>Dan</lastName>
           <loginAttemptsAllowed>0</loginAttemptsAllowed>
           <effectiveDate>2009-04-23 00:00:00.0</effectiveDate>
           <expiryDate>2052-04-26 00:00:00.0</expiryDate>

      </User>

      </Root>

       

      I want to Name as combination of two fields 'firstName lastName'

      i.e.

       

      ADM USER

      Alex Dan

       

      How can I do this?

      Please suggest.

        • 1. Re: Flex 3 Datagrid combine dataField
          RK... Level 3

          Can you try this?

           

          <mx:DataGrid id="dtgUsers" dataProvider="{xmlDP.User}" doubleClickEnabled="true">

               <mx:columns>

                    <mx:DataGridColumn headerText="User Id" dataField="key"/>

                    <mx:DataGridColumn headerText="Name" >

                         <mx:itemRenderer>

                              <mx:Component>

                                   <mx:Label text="{data.firstName} {data.lastName}"/>

                              </mx:Component>

                         </mx:itemRenderer>

                    </mx:DataGridColumn>

               </mx:columns>

          </mx:DataGrid>

           

           

           

           

          public var xmlDP: XML = <Root>

          <User>

                <key>1026</key>

                <firstName>ADM</firstName>

                <lastName>USER</lastName>

                <loginAttemptsAllowed>0</loginAttemptsAllowed>

                <effectiveDate>2009-04-22 00:00:00.0</effectiveDate>

                <expiryDate>2010-04-22 00:00:00.0</expiryDate>      

          </User>

          <User>

                <key>1041</key>

                <firstName>Alex</firstName>

                <lastName>Dan</lastName>

                <loginAttemptsAllowed>0</loginAttemptsAllowed>

                <effectiveDate>2009-04-23 00:00:00.0</effectiveDate>

                <expiryDate>2052-04-26 00:00:00.0</expiryDate>

          </User>

          </Root>

          • 2. Re: Flex 3 Datagrid combine dataField
            Alexander2002 Level 1

            I had done this in following way

             

            Change this line

            <mx:DataGridColumn headerText="Name" dataField="firstName"/>

            to

            <mx:DataGridColumn headerText="Name" labelFunction="nameColumnLabelFunction"/>

             

             

            and following code in page

             

                <mx:Script>
                    <![CDATA[
                        import mx.controls.dataGridClasses.DataGridColumn;
                       
                        public function nameColumnLabelFunction( item : Object, column : DataGridColumn ) : String
                        {
                            return item["firstName"] + " " + item["lastName"];
                        }
                       
                    ]]>
                </mx:Script>