7 Replies Latest reply on Sep 7, 2010 9:21 AM by RosieGp

    Datagrid result value

    RosieGp

      Hi all,

      I have a datagrid pulling data from SQL... Data looks like

      ID          Michigan_Produce      Item

      1           F                               Tea

      2           T                               Apples

      3           T                               Coffee

       

      Now i have a data grid to show this uising flex front end.

       

      The issue is where it says F or T i have to say False or True.

      Is there a way to do that in datagrid itself or i have to write some function...

       

      private

       

       

      {

      function produceResult(event:ResultEvent):void

      if

       

       

       

       

       

      (event.result.length != 0)

      {

      produceResults = event.result

      as ArrayCollection;

      returnData.dataProvider = produceResults;

      }

       

       

      else

      {

      Alert.show(

      "No records exists ");

      }

      }

       

      <mx:DataGrid

       

      id="returnData" width="814" height="282" fontWeight="bold">

       

       

      <mx:columns>

       

       

      <mx:DataGridColumn headerText="ID" dataField="ID" width="75"/>

       

       

      <mx:DataGridColumn headerText="Michigan Produced" dataField="Michigan_Produce" width="75"/>

       

       

      <mx:DataGridColumn headerText="Item" dataField="Item"/>

       

       

      </mx:columns>

       

       

      </mx:DataGrid>

       

       

      Final product should look like:

      ID          Michigan_Produce      Item

      1           False                            Tea

      2           True                             Apples

      3           True                             Coffee

       

      Any help is appreciated...

       

       

        • 1. Re: Datagrid result value
          ShardulSingh Level 3

          Pls try this. It will full fill your requirement.Let me know if u have any issue with this.

           

           

           

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
          <mx:Script>
              <![CDATA[
                  import mx.collections.ArrayCollection;
                 
                  //Let suppose this is from ur arraycollection which is showing the data from server side.
                  private var acFromServerSide : ArrayCollection = new ArrayCollection([
                  {ID: '1',Michigan_Produce : 'T',Item : 'Tea'},
                  {ID: '2',Michigan_Produce : 'F',Item : 'Tea'}
                  ]);
                 
                  [Bindable]
                  private var acModified : ArrayCollection = new ArrayCollection();
                 
                  private function onCC() : void
                  {
                      for each (var obj: Object in acFromServerSide )
                      {
                          if(obj.Michigan_Produce == "T")
                          {
                              obj.Michigan_Produce = "True";
                          }
                          else if(obj.Michigan_Produce == "F")
                          {
                              obj.Michigan_Produce = "False";
                          }
                          acModified.addItem(obj);
                      }
                  }
              ]]>
          </mx:Script>
              <mx:DataGrid id="dg" dataProvider="{acModified}" creationComplete="onCC()">
                     <mx:columns>
                             <mx:DataGridColumn dataField="ID" width="150"/>
                             <mx:DataGridColumn dataField="Michigan_Produce" width="150"/>
                             <mx:DataGridColumn dataField="Item" width="150"/>
                     </mx:columns>
                            
              </mx:DataGrid>
          </mx:Application>

           

           

           

           

           

           

          with Regards,

           

          Shardul Singh Bartwal

          • 2. Re: Datagrid result value
            RosieGp Level 1

            I really appreciate your reply. I did the follwoing but still don't see the populated nothing shows up under Michigan Produce. Am i doing something wrong...

             

            I need that produceResult function as I'm pulling more data for text input columns. Please help...

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
            <mx:Script>
                <![CDATA[
                    import mx.collections.ArrayCollection;

                    private

            var returnData:ArrayCollection;

                 [Bindable] private var acModified : ArrayCollection = new ArrayCollection();

             


              

                  private function produceResult(event:ResultEvent):void {

                           if(event.result.length != 0)

                            {     dg.dataProvider = returnData;}

                           else {Alert.show("No records exists ");}

                      }       
              
                   
                    private function onCC() : void
                    {
                        for each (var obj: Object in returnData )
                        {
                            if(obj.Michigan_Produce == "T")
                            {
                                obj.Michigan_Produce = "True";
                            }
                            else if(obj.Michigan_Produce == "F")
                            {
                                obj.Michigan_Produce = "False";
                            }
                            acModified.addItem(obj);
                        }
                    }
                ]]>
            </mx:Script>
                <mx:DataGrid id="dg" dataProvider="{acModified}" creationComplete="onCC()">
                       <mx:columns>
                               <mx:DataGridColumn dataField="ID" width="150"/>
                               <mx:DataGridColumn dataField="Michigan_Produce" width="150"/>
                               <mx:DataGridColumn dataField="Item" width="150"/>
                       </mx:columns>
                              
                </mx:DataGrid>
            </mx:Application>

             

            • 3. Re: Datagrid result value
              Subeesh Arakkan Level 4

              without modifying the dataprovider you can try something like this using itemrenderer

              <mx:DataGridColumn dataField="Michigan_Produce" width="150"/>
                   <mx:itemRenderer>
                        <fx:Component>
                             <mx:Label label="{data.Michigan_Produce == 'T' ? 'True' : 'False'}" />
                        </fx:Component>
                   </mx:itemRenderer>
              </mx:DataGridColumn>
              
              1 person found this helpful
              • 4. Re: Datagrid result value
                RosieGp Level 1

                @Subeesh,

                I have FB 3 on my machine so when I ran your code it give the folloing error:

                The prefix "fx" for element "fx:Component" is not bound.

                Sorry, im very new to flex, so it takes sometime for me to understand things...

                 

                and in the following code:

                <mx:Label label="{data.Michigan_Produce == 'T' ? 'True' : 'False'}" />

                where did "data." come form, it is dataprovider right???

                • 5. Re: Datagrid result value
                  RosieGp Level 1

                  @Subeesh,

                  I got rid of the error.

                  The code that I'm using now is as following:

                   

                  <mx:DataGridColumn

                   

                   

                  headerText="Michigan Produce" dataField="Michigan_Produce" width="150">

                   

                   

                    <mx:itemRenderer>

                   

                   

                      <mx:Component>

                   

                   

                        <mx:Label text="{data.Michigan_Produce == 'T' ? 'True' : 'False'}" />

                   

                   

                      </mx:Component>

                   

                   

                    </mx:itemRenderer>

                  </mx:DataGridColumn>

                   

                  But this always shows False, even if the value is 'T'. Why is this???

                  Thanks...

                  • 6. Re: Datagrid result value
                    Subeesh Arakkan Level 4

                    data is coming from the dataProvider. Try this for the renderer

                     

                    <mx:itemRenderer>
                         <mx:Component>
                              <mx:Label>
                                   <mx:Script>
                                        <![CDATA[
                                             override public function set data(value:Object):void
                                             {
                                                  super.data = value;
                                                  text = data.Michigan_Produce == 'T' ? 'True' : 'False';
                                             }
                                        ]]>
                                   </mx:Script>
                              </mx:Label>
                         </mx:Component>
                    </mx:itemRenderer>
                    
                    • 7. Re: Datagrid result value
                      RosieGp Level 1

                      Subeesh,
                      Thanks for replying.

                      when i used the follwoing code: The whole application blew off. I did not see anything running... this is driving me crazy...

                       

                      <mx:DataGridColumn

                       

                       

                      headerText="Michigan Produce" dataField="Michigan_Produce" width="75">

                      <mx:itemRenderer>
                           <mx:Component>
                                <mx:Label>
                                     <mx:Script>
                                          <![CDATA[
                                               override public function set data(value:Object):void
                                               {
                                                    super.data = value;
                                                    text = data.Michigan_Produce == 'T' ? 'True' : 'False';
                                               }
                                          ]]>
                                     </mx:Script>
                                </mx:Label>
                           </mx:Component>
                      </mx:itemRenderer>

                      </mx:DataGridColumn >

                       

                      ANy help is appreciated... Thanks in advance.