5 Replies Latest reply on Jul 18, 2008 9:07 AM by ericbelair

    DataGrid concatenate

    wkolcz Level 1
      My app is returning a first name and last name from the database and populating in a datagrid. If I put dataField="leadLastName" it shows the last name, but how can I get it to show "leadLastName, leadFirstName"?

      Something like leadLastName + ", " + leadFirstName? How do you bind that to the dataField?
        • 1. Re: DataGrid concatenate
          SujitG Level 2

          Please check out the labelFunction property of the DataGrid. You can find more details on labelFunction at the URLs below.

          http://livedocs.adobe.com/flex/3/langref/mx/controls/listClasses/ListBase.html#labelFuncti on


          Hope this helps.
          • 2. Re: DataGrid concatenate
            wkolcz Level 1
            Thanks for the info. I checked out the examples, but I am still a little confused.

            I am getting data back from a CFC that populates a datagrid. I am not sure how to create a function that would return the name for each item.

            private function returnHandler(e:ResultEvent):void {
            projectDG.dataProvider = e.result;

            <mx:RemoteObject id="projectGateway" destination="ColdFusion" source="projectmanager.edu.umich.projectGateway" fault="Alert.show(event.fault.faultString, 'Error');" showBusyCursor="true">
            <mx:method name="list" makeObjectsBindable="true" result="returnHandler(event)" />

            For my grid, I have:
            <mx:DataGridColumn headerText="Project Lead" dataField="leadLastName"/>

            Am I to change it to something like:
            <mx:DataGridColumn headerText="Project Lead" labelFunction="getFirstLast"/>


            private function getFirstLast(??):String {
            return ???

            How can I return a string from the function for each record? Does it matter that it changes per listing?

            Thanks for any info!
            • 3. Re: DataGrid concatenate
              ericbelair Level 1
              try something like this:

              private function getFirstLast(item:Object, column:DataGridColumn):String
              return item.firstName + ' ' + item.lastName
              • 4. Re: DataGrid concatenate
                wkolcz Level 1
                Awesome. Worked! Now just have to figure out how to format a date and return it.
                • 5. Re: DataGrid concatenate
                  ericbelair Level 1
                  Using a Label Function, this should work...

                  private function getDate(item:Object, column:DataGridColumn):String
                  // Create a new DateFormatter
                  var dateFormatter:DateFormatter = new DateFormatter();

                  // Set the mask for the DateFormatter
                  dateFormatter.formatString = "YYYY-MM-DD";

                  // Return the formatted date String
                  return dateFormatter.format(item.yourDateField);