4 Replies Latest reply on Mar 1, 2011 1:34 PM by lazurens2011

    CallResponder|Datagrid|delete item from Database

    lazurens2011

      Hello guys,

       

      I succeeded to display datas from database inside the DataGrid using the CallResponder, but until now I still don't know how can I access to the data that already stored in column in the DataGrid !

      the DataGrid Structure is (id, login, password, email, firstname, lastname), and want to access to those datas using the action script

       

      My question, what is the object that already stored these datasin memory? is it "dataProvider", or "data".

      When I want to delete a person from the dataGrid, I want to click on the dataGrid and then click the delete button, the button will seek for the "id" stored in the memory and finaly send the query to the server to delete the item token from the data Grid !

       

      example :

      I click on the second item in the DataGrid, and this item it's id = "14" so dataGrid.selectedIndex == 2, but the value of the attribute of that item is 14

      how can I access to to the values ?

      I face this problem because I don't know where the dataGrid does already stores the data that it displays, and what is the structure of it even it is ArrayList or ArrayCollection.

       

      I hope you understood my challenge?

        • 1. Re: CallResponder|Datagrid|delete item from Database
          Jorge Raimundo Level 2

          The data is stored in the dataProvider (or at least that's what I usualy use).

           

          As for the delet question, you'll have to make GridItemRenderer with a button that dispatches an event (don't forget to set the bubbles to true) with the item id or row index.

           

          Then the application must catch that event and take care of the deletion.

          • 2. Re: CallResponder|Datagrid|delete item from Database
            lazurens2011 Level 1

            Thank you for the fast reply,

            I would ask you, can you please tell me how can I manipulate the dataProvider ? for example push it or convert it into an ArrayCollection, because until now, I can't manipulate and access the datas that I have from the database , I want to select the "id" alone from the list of items listed in the dataGrid, my Idea was to take all the data the same stored in the dataGrid and put them in an ArrayCollection and then I'll be able to do what I want by accessing directly to the Array thanks to the selectedIndex of the dataGrid.

            What do you think, and please if you have other method help me with it,

            and thank you again,

            • 3. Re: CallResponder|Datagrid|delete item from Database
              Jorge Raimundo Level 2

              Ok, I do not know how you are getting your data, but I'll give it a shot.

               

              Most probably the DataGrid's dataProvider is already an ArrayColection.

              If it is, you can access its data by using the getItemAt(index:int) method.

              Note that you'll get an Object. If you want the property you'll hav to use dataGrid.dataProvider.getItem(0).id .

               

              But the best way to check what things are is to debug your project. Set a breakpoint in a place where you have visibility to the dataGrid and when debugging it you can watch the datagrid, see what the dataProvider is and it's contents.

              1 person found this helpful
              • 4. Re: CallResponder|Datagrid|delete item from Database
                lazurens2011 Level 1

                Thank you a lot, that is correct, I executed the application in debug mode and I saw that the dataProvider is already an ArrayCollection, so I can understand that all the method of an Arraycollection is already applyable to the dataProvider.

                I didn't know that it is the case, so before you reply me, I was thinking about doing that manually, by pushing the result that come from the CallResponder into an ArrayCollection that is already declared manually in the mxml file, after that adding an event listener and calling a function that is going to make a loop and store all the result into a the ArrayCollection.

                 

                Here is the code: (I think it is useful if someone is going to select something manually from the database so he has to do the same thing and filtring the results inthe loop)

                 

                 

                Creating Manulally the dataProvider()

                Script :

                protected function dataGrid_creationCompleteHandler(event:FlexEvent):void

                {

                getAllUserResult.token = userService.getAllUser();

                getAllUserResult.addEventListener(ResultEvent.RESULT,onResult);

                }

                protected function onResult(event:ResultEvent):void

                {

                 

                for (var i:int=0 ;i< event.result.length;i++){

                userMemory.addItem(event.result[i]);

                }

                 

                }

                Mxml File (Declaration) :

                <fx:Declarations>

                <s:CallResponder id="getAllUserResult"/>

                <userservice:UserService id="userService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>

                <s:ArrayCollection id="userMemory"/>

                </fx:Declarations>

                 

                I must thank you my brother for the answer, and for the fast reply !