12 Replies Latest reply on May 28, 2008 2:59 AM by laurent_pinson

    AdvancedDataGrid doesn't update?

    mark416 Level 1
      Hi,

      I am working with cairngorm with Flex 3.

      I use Datagrid before in the page and it works fine.The Datagrid
      automatically update with the data updated in database when I reopen the page.

      ...
      <mx:DataGrid x="15" y="72" width="581.5" height="239"
      dataProvider="{ModelLocator.QModel}">
      <mx:columns>
      <mx:DataGridColumn headerText="Name" dataField="Name"/>
      <mx:DataGridColumn headerText="Department"
      dataField="Department"/>
      </mx:columns>
      </mx:DataGrid>
      ...

      I just use AdvancedDataGrid to raplace DataGrid and add grouping
      feature.But it has a problem now.


      <mx:AdvancedDataGrid x="15" y="72" width="581.5" height="239"
      rowCount="4" initialize="gc1.refresh();" >

      <mx:dataProvider>
      <mx:GroupingCollection id="gc1" source="{ModelLocator.QModel}">
      <mx:grouping>
      <mx:Grouping>
      <mx:GroupingField name="TypeName" />
      </mx:Grouping>
      </mx:grouping>
      </mx:GroupingCollection>

      </mx:dataProvider>



      <mx:columns>
      <mx:AdvancedDataGridColumn headerText="Name"
      dataField="Name"/>
      <mx:AdvancedDataGridColumn headerText="Department"
      dataField="Department"/>

      </mx:columns>
      </mx:AdvancedDataGrid>


      The problem is the AdvancedDataGrid doesn't update even if data
      updated in database when I reopen the page.

      Please give me a idea how to fix this and why this happen for AdvancedDataGrid.

      Thanks for your help in advance

      Mark
        • 1. Re: AdvancedDataGrid doesn't update?
          Sreenivas R Adobe Employee
          I am unable to guess what you mean by reopening the page.

          GroupingCollection has logic in place to listen to source collection changes and act accordingly. But if ModelLocator.QModel is an Array or something else which won't fire change events GC has no way of knowing the source has changed.
          • 2. Re: AdvancedDataGrid doesn't update?
            make sure ModelLocator.QModel has changed ???
            • 3. Re: AdvancedDataGrid doesn't update?
              laurent_pinson Level 1
              you need to use <your AdvancedDatagrid>.validateNow() just after :p
              • 4. AdvancedDataGrid doesn't update?
                mark416 Level 1
                'reopening the page' means access the same page after the data are changed.

                I am sure the ModelLocator.QModel already are changed the is the arraycollection.

                "<your AdvancedDatagrid>.validateNow() just after :p ",I do not understand what this means,Please help me.

                Thanks a lot

                Mark
                • 5. Re: AdvancedDataGrid doesn't update?
                  laurent_pinson Level 1
                  well, i think you just need to call the validateNow method of AdvancedDataGrid class after updating your dataprovider.

                  That's how it works for me
                  • 6. Re: AdvancedDataGrid doesn't update?
                    mark416 Level 1
                    how to call validateNow method of AdvancedDataGrid?

                    gc.validateNow

                    do you think if it is the right syntax?Thanks

                    • 7. Re: AdvancedDataGrid doesn't update?
                      laurent_pinson Level 1
                      gc.validateNow()

                      Mhmm in mxml, i don't see how you could do that. Maybe if you can listen to some "dataprovider update" event, you could then activate this method.

                      In actionScript, it's easier :p
                      • 8. AdvancedDataGrid doesn't update?
                        laurent_pinson Level 1
                        I am "reopening" with topic because in fact i have the same problem =_=.

                        Mhmm i display an advancedDataGrid with several buttons in the header :
                        - add element
                        - delete element(s)
                        - refresh

                        Well basically, "refresh" is just giving to my advancedDataGrid.provider a new instance of HierarchicalData (that i populated with an ArrayCollection). I can refresh or select different HierarchicalData, it will always display the good values. It works perfectly and i don't need to use "validateNow".

                        quote:


                        private function updateDisplay(arr:Array):void{
                        var hd:HierarchicalData = new HierarchicalData();
                        hd.source = new ArrayCollection(arr);
                        dataGrid.dataProvider=hd;
                        }



                        "Add element" and "delete element" work perfectly if i add or delete an element in the root... but if it's in some nodes, advanceDataGrid doesn't update whereas the dataprovider is updated (when i look with debug tools).

                        quote:


                        private function onDelItem(e:Event):void{
                        var hd:HierarchicalData = new HierarchicalData();
                        hd.source = dataGrid.dataProvider.source.source;
                        var selections:Array = dataGrid.selectedItems;
                        for(var index:* in selections){
                        hd.source = new ArrayCollection(deleteHierarchicalItem(selections[index],(hd.source as ArrayCollection).toArray()));
                        }
                        dataGrid.dataProvider=hd;
                        (dataGrid.dataProvider as HierarchicalCollectionView).refresh();
                        dataGrid.validateNow();
                        dataGrid.validateDisplayList();
                        }


                        Adding element is not a problem as i will always add them at the end of the tree in the root and use the drag & drop to arrange them in my tree. But i need to delete items at different depth

                        What do i miss ? :(

                        • 9. Re: AdvancedDataGrid doesn't update?
                          Sreenivas R Adobe Employee
                          I am unable to guess what would be the problem behind the behavior you are seeing.

                          I wrote the attached sample code and it seems to work correctly.
                          • 10. AdvancedDataGrid doesn't update?
                            laurent_pinson Level 1
                            Thanks for you help,

                            Yes it works, maybe because you use GroupingCollection instead of HierarchicalData. Unfortunately, i can't use GroupingCollection because sometimes all the "groupingfield" values of an object are not set and so it creates some strange display.
                            With GroupingCollection all the leaves must have the same dept.

                            You can observe it in you example if you just replace you addItemToSource function by this one
                            private function addItemToSource():void{
                            gc.source.addItem({name:person.text, email:email.text});
                            }

                            That's why I have to use HierarchicalData. I need to have leaves at different depth.

                            But as i said before adding items is not a problem for me as I will just add them a the top (depth = 0) and then use drag&drop to put them into nodes (depth > 0). The problem is when I delete leaves that have non-zero depth. As the debug tool shows me, the value are good in the dataprovider but the tree displaid is not updated.

                            Hoping I am understandable (I am French ^^"), thanks a lot.

                            edit: I will try to add an example tonight.
                            • 11. Re: AdvancedDataGrid doesn't update?
                              Sreenivas R Adobe Employee
                              For HierarchicalData make sure that all the children elements are also ArrayCollections and not simple Arrays. Simple Arrays donot dispatch any event on add/removeItems making it impossible to detect any changes to them.
                              • 12. AdvancedDataGrid doesn't update?
                                laurent_pinson Level 1
                                Aaaaah, thank you very much that was the problem ^^

                                Now when I delete an item using ArrayCollection.removeItemAt(), a CollectionEvent.REMOVE event is emitted and the problem solved =)

                                Thank you very for your help

                                Laurent