3 Replies Latest reply on May 1, 2009 12:19 PM by EvolvedDSM

    FilterFunction on datagrid AC causing null update values

    EvolvedDSM Level 2

      I'm trying to update values of a datagrid.  I use a form with fields that bind to the selectedItem values of the datagrid.  Then I submit the form and it updates the record according to what's in the fields.  This works fine with the code I have.

       

      I added a filterFunction on the arrayCollection of the datagrid to help with searching through hundreds of records.  The filterFunction properly filters the search criteria and displays the matching values in the datagrid.  I select the record from the filtered list and the form fields populate correctly.  Now, if I want to change a field value to something else and hit update, the record takes on null values for every field value that comes after the changed field.  Let me provide my code to help explain better.

       

      I have an UPDATE button on the form that calls updateHistory() function.

       

      private var upObj:editHist; //declares upObj as the valueObject 'editHist'

      private var ac:arrayCollection; //contains values as a result of a remoteObject call

       

      private function updateHistory():void{
                          upObj = new editHist();
                          upObj = editHist(histDG.selectedItem); // sets upObj to take on the current values of the selectedItem in the datagrid
                          upObj.clientName = clientNameInput.text;
                          upObj.caseWorker = caseWorkerInput.text;
                          upObj.actionRequired = actionRequiredInput.text;
                          upObj.timeIn = timeInInput.text;
                          ac.itemUpdated(upObj);  // ac.setItemAt() also gives me the same issue

                  }

       

      If no values are changed on the form when hitting UPDATE, nothing happens or the item is just updated with what was contained in the fields.  Now, on my form field -- if I change only the clientNameInput value and hit UPDATE, the record will update to show the new clientName value, but the other values become NULL.  If I changed the value of caseWorkerInput and hit update, the record retains the unchanged clientName value and updates the new caseWorker value, but then the values after that become NULL.  So, what I've noticed is that any value in my updateHistory function that gets changed will update that value, but any of the following values after that get set to NULL.

       

      For a cheap example, let's give a record default values in the arrayCollection of

      "Bob" for clientName

      "Joe" for caseWorker

      "Testing" for actionRequired

      "9:30 AM" for timeIn

      If I change the caseWorker from Joe to Frank, the record will reflect "Bob", "Frank", NULL, NULL.  If I changed timeIn to 10:00 AM instead of 9:30 AM, the record reflects "Bob", "Joe", "Testing", "10:00 AM" (no change since there are no values after timeIn within my updateHistory function.  If I change the clientName from "Bob" to "Ted", it will make the three values after that NULL.  I have tried switching around the values in my function, but it all acts the same way.  So in the order that these values appear to be set in my function is the order in which NULL values appear after the first changed value.  If I change two values in the same update, the first changed value in the function will update properly, but it ignores my change to the other value and just makes it NULL as I described above.

       

      So I am not sure if I'm properly setting my valueObject correctly and then setting the values to the valueObject's properties correct either, but I need some help.  It shouldn't be acting this way.

        • 1. Re: FilterFunction on datagrid AC causing null update values
          ATIF FAROOQ Level 3

          hi,

             what if you update History like this

           

                      var upObj:Object
                      private function updateHistory():void{
                           upObj = histDG.selectedItem
                           upObj.clientName = clientNameInput.text;
                           upObj.caseWorker = caseWorkerInput.text;
                           upObj.actionRequired = actionRequiredInput.text;
                           upObj.timeIn = timeInInput.text;
                           ac.itemUpdated(histDG.selectedItem);  
                     }
          
          • 2. Re: FilterFunction on datagrid AC causing null update values
            EvolvedDSM Level 2

            I just tried casting the record as an object and not as a valueObject and it's still losing the values when I'm filtering the AC.  I replaced the itemUpdated() line with Alert.show(histDG.selectedItem.actionRequired), then made a change to the clientName field and ran the update.  Flash Player returns "TypeError: Error #1009: Cannot access a property or method of a null object reference."  So the value for actionRequired is NULL.  Now if I don't make any changes after selecting the record and just leave everything as it was and UPDATE, it returns the correct actionRequired value.  So on value change, the other values become Null.  DOES NOT MAKE SENSE!!!

             

            Here's the filterFunction code:

             

            There's a text Input that allows search criteria with an id property of 'histTextFilter' and a change property of filterHistory().

             

            private function filterHistory():void{

                ac.filterFunction = histFilter;

                ac.refresh();

            }

             

            private function histFilter(obj:Object):Boolean{

                var isMatch:Boolean = false;

                if(obj.clientName.toLowerCase().search(histTextFilter.text.toLowerCase()) != -1){

                      isMatch = true;

                }

            }

             

            So every time a character is added, removed, etc in the histTextFilter field, it calls filterHistory().  That function looks to histFilter(obj) to determine if the clientName column of the DG contains the criteria of the search input.  If it does, it filters.  The filter works perfectly, and I don't think I've had problems using it in the past with update functions.

             

            Soon as I change a value in the form, all other values after that in the update function just get set to NULL value.  Very confused on this.

             

            Again, the update function works fine when the arrayCollection is not filtered.

            • 3. Re: FilterFunction on datagrid AC causing null update values
              EvolvedDSM Level 2

              I am working around this problem.

               

              • added an itemClick property to the datagrid which calls the function below

               

              private function selectItem():void{
                      if(ac.filterFunction != null){
                          var selObj:Object = histDG.selectedItem;
                          histTextFilter.text = '';
                          ac.filterFunction = null;
                          ac.refresh();
                          var ind:int = ac.getItemIndex(selObj);
                          histDG.scrollToIndex(ind);
                          histDG.selectedItem = selObj;
                      }
                  }

               

              This wipes out the filterFunction while retaining the record I've selected while the filter was applied to the datagrid/ac.  The datagrid repopulates without the filterfunction and my selectedItem record retains its selection and the dg scrolls to the record.  I can then update data in the form as needed and everything works as it should.

               

              Still curious why the values turn to null during the filterFunction without this work-around though.  Just strange.  I'll leave this thread open if someone has some insight on the issue.