0

I have a Ext.Window which is called inside a function. I pass a parameter to window through function. When I try to re-open window with a new value, window performs operations with the old value.

Here is my code -

var Win;
LoadWindow = function (id) {
if (!Win) {
    Win = new Ext.Window({
        id: 'Pop-win',
        layout: 'fit',
        width: 650,
        modal: true,
        height: 450,
        closeAction: 'close',
        plain: true,
        items: [Panel],
        listeners: {
            close: function (w) {
               Win.removeAll();
            },
            show: function (p) {
                Store.reload({
                    params: {
                        'ID': id
                    }
                });
            }
        }
    });
}
Win.show();
}

PS: I Use extjs 3.4 version

1
  • if (!Win) will prevent the creation of a new window, so Win will always be the first window no mather what you pass in id
    – Shlomo
    Feb 27, 2014 at 8:50

1 Answer 1

0

Move the Store.reload(); part out of the show listener. The id it refers to is always referring to the first time you create the window.

If this window is not being used too often, it might suffice to simply change it to use closeAction: 'destroy' so that you generate a new window each time. If you need to reuse it, write a helper function on the window that reloads the store separately, and call Win.customStoreReload() followed by Win.show(). By the way, closeAction: 'close' is also not a valid closeAction. The config can only be set to either 'destroy' or 'hide'.

LoadWindow = function (id) {
    if (!Win) {
        Win = new Ext.Window({
            id: 'Pop-win',
            layout: 'fit',
            width: 650,
            modal: true,
            height: 450,
            closeAction: 'hide', // either 'hide' or 'destroy'. 'close' is not a valid option
            plain: true,
            items: [Panel],
            listeners: {
                close: function (w) {
                    Win.removeAll();
                }
            }
        });
    }
    Store.reload({params: { 'ID': id }});
    Win.show();
}
3
  • suppose, I have a <a href> in a .js file from where I call LoadWindow(id). This id may be different each time. So I want to open a new window for each id. So I cant avoid loading store in show:
    – Sandy
    Feb 28, 2014 at 7:11
  • Have you tried using closeAction: 'destroy'. The problem right now is you are keeping the window in memory and calling the same one each time, so the "id" that's tied to your show listener is never actually renewed (it is only set on construction if that makes sense). It uses the id from your first instantiation. If you are looking to reuse the window, you would need to call a separate function that actually reloads the store manually before each window showing.
    – Kuma
    Feb 28, 2014 at 19:09
  • I've added code to explain my answer a bit more. Assuming you are only ever showing the window through the LoadWindow function, I see no reason why moving the Store.reload out of the show would not work. That being said though, I am assuming you have the store tied to the window somewhere else in your code, and that is being handled properly already just by loading the store.
    – Kuma
    Feb 28, 2014 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.