3 Replies Latest reply on Sep 24, 2007 1:08 AM by JehMus

    String compare in a datagrid

    KomputerMan.com Level 1
      I have a datagrid that contains both integers and text fields. The text fields are customer names and the integer fields are claim numbers beginning with a Year (I.E. 20010005 is a valid entry here). I also have two text boxes on a form that I want to use to compare to the values in the datagrid. So if a user types in the letter "A" in the Last Name text box my script goes and finds all records in the datagrid where tha LastName starts with the letter A. This is working well.

      My problem is when I type something into the claim number text box my script fails. I am pretty sure that it has something to do with the fact that the data being stored in the datagrid is a number and I am trying to do a string compare. Being kind of new to AS I could use a little help here. My question is how do I cast the item.ClaimNum field to a string so I can compare the value in the text box to the integer stored in my database?.

      Here is the AS I have so far.

      private function catFilter(item:Object):Boolean
      {
      var result:Boolean=false;

      var pattern:RegExp= new RegExp("^","i");
      var pattern1:RegExp= new RegExp("^"+LName.text,"i");
      var pattern2:RegExp= new RegExp(ClaimNum.text,"i");

      if ((LName.text != "") && (ClaimNum.text == ""))
      {
      return item.LName.match(pattern1);
      }
      else if ((LName.text == "") && (ClaimNum.text != ""))
      {
      return item.ClaimNum.match(pattern2);
      }
      else
      {
      return item.LName.match(pattern);
      }
        • 1. Re: String compare in a datagrid
          inlineblue Level 1
          Use ClaimNum.toString() to convert to string.
          • 2. Re: String compare in a datagrid
            KomputerMan.com Level 1
            Thanks for the reply inline... That is what I ended up doing in my CFC template. I'll play with it and make it work in AS too now that I know what to look for. Who woulda thunk it... an AS command that is the same as a CF command... :)

            Have an Ordinary Day...
            KomputerMan ~|:-)
            • 3. Re: String compare in a datagrid
              JehMus
              Hello,

              I am new to ActionScript. Can you tell me how can I access the rows and columns of a data grid?

              What I want to do is that when the application load, I will populate the datagrid with the Xml returned from the webservice. After that, webservice will be called periodically (using timer) and the information in the datagrid needs to be updated. The cells which are updated need to be highlighted.

              The datagrid actually contains the stock market data (symbol name and its other attributes). So once the datagrid has been populated on application creation, it contains all the symbols in the market. After that, only attributes of the symbols will change, like price, volume etc. What I want is that once the datagrid is populated, i can access the row by using the value of symbol code and then update the appropriate columns of that symbol. (Xml from next time will contain only symbols whose values change from last time).

              Below is the code that I have written so far.

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
              creationComplete="OnAppCreationComplete()" width="100%" height="100%">

              <mx:Script>
              <![CDATA[
              import mx.rpc.events.ResultEvent;

              private var count:uint = 0;
              private var messageFramXmlList:XMLList;
              private var marketSnapshotTimer:Timer = new Timer(1000);

              private function OnAppCreationComplete() : void
              {
              this.ajaxServiceInvokerProxy.addEventListener(ResultEvent.RESULT, this.OnWebServiceResultArrived);
              this.ajaxServiceInvokerProxy.InvokeService.send();

              this.marketSnapshotTimer.addEventListener(TimerEvent.TIMER, this.OnSnapshotTimerTick);
              this.marketSnapshotTimer.start();
              }

              private function OnWebServiceResultArrived(event:ResultEvent) : void
              {
              var marketSnapshotXml:XML = new XML(event.result);
              this.messageFramXmlList = marketSnapshotXml.child("MarketSnapshot").child("MessageFrameList")[0].child("MessageFram e");

              this.dgTopPosts.dataProvider = this.messageFramXmlList;
              this.btnCounter.label = this.count.toString();
              }

              private function OnSnapshotTimerTick(event:TimerEvent) : void
              {
              this.count++;
              this.ajaxServiceInvokerProxy.InvokeService.send();
              }
              ]]>
              </mx:Script>

              <mx:WebService id="ajaxServiceInvokerProxy"
              wsdl=" http://jehanzeb/ajaxserviceinvoker/ajaxserviceinvoker.asmx?wsdl"
              useProxy="false">
              <mx:operation name="InvokeService">
              <mx:request>
              <serviceWithComonentName>DetailedSnapshotComponent.MarketSnapshot@TADAWUL</serviceWithCom onentName>
              <parametersXml><![CDATA[ <Parameters/> ]]></parametersXml>
              </mx:request>
              </mx:operation>
              </mx:WebService>

              <mx:Panel x="10" y="10" width="100%" height="100%" layout="absolute" title="Market View">
              <mx:RichTextEditor id="txtMarketViewResult" x="10" y="10" width="612" height="194" />

              <mx:DataGrid x="10" y="223" id="dgTopPosts" width="100%" height="303">
              <mx:columns>
              <mx:DataGridColumn headerText="Symbol Code" dataField="SymbolID" />
              <mx:DataGridColumn headerText="Last Time" dataField="LastTime" />
              <mx:DataGridColumn headerText="Net Change" dataField="NetChange" width="75"
              />
              <mx:DataGridColumn headerText="Percent Change" dataField="PercentChange" width="75" />
              <mx:DataGridColumn headerText="Previous Closed" dataField="PreviousClosed" width="75"/>
              <mx:DataGridColumn headerText="Close" dataField="Close" width="75"/>
              <mx:DataGridColumn headerText="Direction" dataField="Direction" width="75"/>
              <mx:DataGridColumn headerText="BidPrice" dataField="BidPrice" width="75"/>
              <mx:DataGridColumn headerText="AskPrice" dataField="AskPrice" width="75"/>
              <mx:DataGridColumn headerText="BidVolume" dataField="BidVolume" width="75"/>
              <mx:DataGridColumn headerText="AskVolume" dataField="AskVolume" width="75"/>
              </mx:columns>
              </mx:DataGrid>
              <mx:LinkButton id="btnCounter" x="10" y="528" width="306" textAlign="left" label="" />
              </mx:Panel>
              </mx:Application>