6 Replies Latest reply on Jan 26, 2009 4:26 AM by akost01

    Best way to prevent Collection from update?

    akost01
      I have a problem/question regarding the dataGrid, see attatched code.

      When I click on a row in the lower grid I want to copy the information to the upper grid. When I edit the cell(s) in the upper grid I don't want the lower grids collection to be updated.

      If I use the attatched code and edit a cell, the collection in the lower grid updates when I scroll the rows up and down (in the lower grid).

      The only way I can prevent this update is to set the dataProvider to "[{colA: dataGrid1.selectedItem.colA, colB: dataGrid1.selectedItem.colB, colC: dataGrid1.selectedItem.colC}]" instead of "dataGrid1.selectedItem".

      Is this a bug or what am I doing wrong? It should be a better way to prevent the collection from being updated. I have tried different events to both check if/when the collection is updated but no success here. I can't get the "preventDefault()" function to work either.

      Any solution/suggestion?

      Regards,

      the newbe from Sweden...
        • 1. Re: Best way to prevent Collection from update?
          ntsiii Level 3
          If you bind to the collection (dataProvider="{arr}"), changes made to the collection will display in the UI. this is the intent of binding

          If you do not want this, do not bind, or bind to an independent collection that you update manually.
          • 2. Re: Best way to prevent Collection from update?
            Level 7

            "ntsiii" <tspratt@lariatinc.com> wrote in message
            news:gkqhdj$6c9$1@forums.macromedia.com...
            > If you bind to the collection (dataProvider="{arr}"), changes made to the
            > collection will display in the UI. this is the intent of binding
            >
            > If you do not want this, do not bind, or bind to an independent collection
            > that you update manually.

            I think you can also temporarily turn off automaticupdate on the
            ArrayCollection.

            HTH;

            Amy


            • 3. Re: Best way to prevent Collection from update?
              ntsiii Level 3
              I think that is correct.

              But the original poster should examine his logic. If the UI component should not reflect the values in a data model, then it should probably not use that data model as the dataProvider.

              If this is just the need to temporarily delay the UI display update, then yes, setting automaticUpdate makes sense.
              • 4. Re: Best way to prevent Collection from update?
                akost01 Level 1
                Thanks for your replyes!

                What I', trying to to is just to copy the data from one row in dataGrid1 to dataGrid2. I then want to edit the data in dataGrid2 without the data in dataGrid1 is getting updated. I don't want any binding!

                If I chage the code 'dataProvider="{arr}"
                ' to 'creationComplete="dataGrid1.dataProvider=arr"' and also insert the code 'itemEditEnd="arr.disableAutoUpdate()"' for dataGrid2 I still get the same "binding" as stated before.

                What am I doing wrong?

                Regards,
                • 5. Re: Best way to prevent Collection from update?
                  ntsiii Level 3
                  You need two independent dataProviders, one for each grid. then you need to make a *copy* of the data row before you put it in the second dataProvider. This is because just assigning the object(selectedItem) will just set a reference to the same object.

                  You could use ObjectUtils.copyObject(), or simply create a new Object() and assign the properties and values to the new object, then addItem() to the second dataProvider.
                  • 6. Re: Best way to prevent Collection from update?
                    akost01 Level 1
                    OK, thanks - I will try that!