2 Replies Latest reply on Mar 22, 2010 10:33 PM by Flex harUI

    How to use substring and lastindexof() in datagrid..?

    Ling's

      hi.,

       

        To check the datagrid datacolumn file is .txt , .doc or .pdf. to binding different images using sub string ,lastindexof or match(patterns).

      Any one help this code....

       

      code:

       

      <mx:DataGridColumn width="20" resizable="false"  >
            <mx:itemRenderer>
                    <fx:Component>
                         <mx:HBox>
                                                        <fx:Script>
                                                              <![CDATA[
                                                                 
                                                                  [Embed(source="assets/doc.gif")]
                                                                  [Bindable]
                                                                  public var wordImage:Class;
                                                                 
                                                                  [Embed(source="assets/txt.gif")]
                                                                  [Bindable]
                                                                  public var txtImage:Class;
                                                                 
                                                                  [Embed(source="assets/pdf.gif")]
                                                                  [Bindable]
                                                                  public var pdfImage:Class;
                                                                 
                                                                  private function determineImage(str:String):Class
                                                                  {
                                                                      var returnImage:Class
                                                                      //var txtdoc:String = str;
                                                                     
                                                                      var txtdoc:Number = str.lastIndexOf( '.doc' );
                                                                      if ( txtdoc != -1 )
                                                                      {
                                                                          return wordImage;
                                                                      }
                                                                      else( txtdoc == -1 )
                                                                      {
                                                                          return txtImage;
                                                                      }
                                                                     
                                                                      return returnImage;
                                                                    ]]>

       

                                                          </fx:Script>   
                                                           <mx:HBox >
                                                          <mx:Image source="{determineImage(data.document_long_name)}"    toolTip="{data.document_long_name}                                                        Notes"  buttonMode="true" />
                                                      </mx:HBox>
                                                          </mx:HBox>
                                                        </fx:Component>
                                                 
                                              </mx:itemRenderer>
                                              </mx:DataGridColumn>

       

      With Regards.,

      LinFlex-