Thursday, April 28, 2011

What events can I catch when the user leaves a GXT grid?

I have a web app that uses GXT (version 1.2.2) grids extensively. I'd like to warn the user if they make changes but don't save.

When I use the grid in a popup dialog, the only way for the user to leave is via a button (either Close or OK). If I add a SelectionListener to the Close button, I can do my "isDirty()" check and warn the user.

If I am not using a dialog, the restriction for leaving the page isn't there. The user can click on a side menu, select a different tab, hit a refresh or next page button that we have on each page. I could listen for an event on everyone of those, but is there an easier way? Something like a "before unload" event that gets fired?

From stackoverflow
  • Window.addCloseListener

    Or in GWT 1.6:

    Window.addCloseHandler

    You cannot prevent the window from closing, but you can prompt the user to click cancel which will leave the page open. You can also perform a last-chance save operation after the user chooses to confirm the window close, but before your page is unloaded.

    CoverosGene : I tried this, but it didn't work, I assume since the window isn't closing. I'm just going to another grid or tab or page.
    Mark Renouf : I see. If the Grid is indeed unloading, then your only hope is hooking the onDetach() method on the the Widget. There's no listener so you'd have to overload it within a subclass. If the tab is changed, but the grid remains hidden, then you're completely out of luck and must listen to everything.

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.