Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    OnTabSelected fire an event to fetchData in a ListGrid

    Hi,

    probably my issue is not as difficult as I think it is
    but I'm working on this issue for more than 16 hours by
    now.

    What I want to do is the following:
    I placed a ListGrid on a Tab and fetched the data
    automatically. Now the user could open some other
    tabs and edit data but as soon as the user get's back to
    the Tab with the ListGrid I want to fire an event to
    fetch the data for this ListGrid.

    Could someone help me with this issue. I'm not too
    familiar with custom events. Maybe a little HowTo
    would already help but so far I couldn't find a tutorial
    for custom events for smartgwt.

    If my approache is totaly wrong just let me know how you
    would handle this issue.

    By the way the reason why I can't use the OnTabSelected
    event directly is that the ListGrid is not a child of the
    tab itself but it's a child of the child of the child of the
    Tab.

    I hope my english is not to bad to get the idea of what I
    want to do.

    Thanks in advance
    Phillip

    #2
    Good Morning,

    I am having the same question that was previously asked.

    I have a listgrid in a tab...and I have 2 tabs. I would like to refresh the list grid with the criteria that it was originally populated with when the Tab is selected.

    I tried using OnTabSelected as shown below and I haven't had much success.

    May someone please help me or point me in the right direction. Thank you so much.

    Code:
     Tab viewDeleted = new Tab("Deleted");  
            viewDeleted.setIcon("silk/application_form.png");  
            viewDeleted.setWidth(70);  
            viewDeleted.setPane(deletedManifest);
            viewDeleted.addTabSelectedHandler(new TabSelectedHandler() {
    
    			@Override
    			public void onTabSelected(TabSelectedEvent event) {
    				// TODO Auto-generated method stub
    				final DeletedManifestList list = (DeletedManifestList)event.getTabPane();
    				
    				DSCallback callback = new DSCallback(){
    				    @Override
    				    public void execute(DSResponse response, Object rawData, DSRequest request){
    				        list.setData(response.getData());
    				    }};
    				
    					AdvancedCriteria criteria = new AdvancedCriteria(OperatorId.AND, new Criterion[]{
    						   new Criterion("ProjectId", OperatorId.EQUALS, project.getValueAsString())
    					});
    					
    					list.fetchData(criteria, callback);
    					event.getTab().setPane(list);
    				
    			}
            });
    I am using SmartGwt 3.0p 08052012 Power Edition, on Firefox 10.0.

    Any help is appreciated and thank you in advance.

    Comment


      #3
      Just updating on my issue and looking for some guidance,

      I followed other suggestions on different posts to use the function ListGrid.invalidateCache().

      However, I have read several times that the use of invalidateCache is not a preferred method.

      My code looks as follows now:
      Code:
      viewDeleted.addTabSelectedHandler(new TabSelectedHandler() {
      
      			@Override
      			public void onTabSelected(TabSelectedEvent event) {
      				// TODO Auto-generated method stub
      				final DeletedManifestList list = (DeletedManifestList)event.getTabPane();
                                      list.invalidateCache();
                               list.fetchData(list.getCriteria());
      			}
              });
      With the code above I get the desired results of having the listgrid refresh everytime the tab is selected, but my question is the following......
      Is there a more correct or desirable way of accomplishing my requirement? If so, may you please advise?

      Any help or comments are appreciated.
      Thank you in advance.

      Comment


        #4
        If what you want to do is reload data from the server *because of changes by other users*, invalidateCache() is appropriate for this, but there is no need to call fetchData() after calling invalidateCache().

        It's incorrect to use invalidateCache() if you are trying to solve a problem where changes are saved by the current user and that user's grids (or other components) do not reflect the changes the user just made. For that problem, see the FAQ about grids not updating automatically.

        Comment


          #5
          Isomorphic thank you for your reply.

          I guess I might as well with your comment then paint the whole picture and hopefully you and/or anyone else can suggest to me if I have taken the correct approach.

          I have had a listgrid showing entries for a long time, where a user myself or others, can add/remove from that list, and recently a requirement came about where everyone would like to know what entries have been deleted from the ListGrid.

          So as a simple solutions I replicated the Listgrid table (Manifest) and created (Deleted Manifest).
          So on the ds.xml file for "Manifest", I set a customSQL for the operationType="remove" where my customSQL calls a procedure I created which contains a mysql transaction....
          For example:
          Code:
          INSERT INTO Deleted_Manifest ....
          DELETE FROM Manifest WHERE ....
          So I have two tabs "Current" and "Deleted", each having separate datasources (i.e. Manifest, Deleted Manifest) respectively.

          So when I delete an entry from the Manifest Listgrid, the listgrid in fact refreshes and no longer shows the entry that was selected for removal.

          However, when I select the "Deleted" tab, that recently removed entry from the "Current" tab was not showing up in the Deleted listgrid. Hence, my previous post asking if using invalidateCache on the "Deleted" listgrid/tab through OnTabSelected, is the correct approach I should take. Ultimately what is needed is, when one deletes from the Manifest Listgrid (Current Tab), refresh the Manifest Listgrid as also refresh the Deleted Manifest Listgrid.

          Sorry for the lengthy post I just thought the extra detail might in fact be helpful to others with similar requirements.

          So once more, is using "invalidateCache" the correct approach in this instance?

          Thanks in advance.
          Last edited by ajmarrer; 15 Nov 2012, 09:48.

          Comment


            #6
            No, this does not sound like a situation where invalidateCache() is appropriate, because it is not the case that *other users* are modifying the list of deleted items.

            There are multiple ways to track a list of deleted items, in this case, you seem to have set up a DataSource that can fetch them.

            In that case, you could use DataSource.updateCaches() to tell the system that a new record has been added to the DataSource that holds the list of deleted items. This avoids an extra server trip that (needlessly) reloads the entire list even though only one new entry needs to be added and you already have the necessary information to add it.

            Comment

            Working...
            X