Skip to content

Put grid object in global scope even when loaded via Ajax #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

colinmollenhour
Copy link

Mass actions in an ajax-enabled grid are broken when the grid container is loaded via ajax such as in an ajax-enabled tab. Adding window to the variable declaration forces it to be in the global scope so the following ajax requests can access the grid object.

@colinmollenhour
Copy link
Author

Btw, this also affects Magento 1.x..

@magento-team
Copy link
Contributor

Please, clarify what exact grid is broken (what steps to replicate this issue, if possible, please, provide error message) that we could go deep into a problem.

@colinmollenhour
Copy link
Author

Not sure if there is a grid in core code that is broken due to this issue; I noticed it in a grid in a custom module. Please see my original description for the issue as I think the description and the patch explain it thoroughly enough as long as one understands how Javascript scopes work and that code executed as a part of html from an Ajax response doesn't get executed in the global scope like it does if rendered as part of the page's original HTML..

@magento-team
Copy link
Contributor

Hi Team. We checked our grids and they worked properly. We close this issue as you didn't mention core modules in the thread. Thank you!

@joshdw1
Copy link

joshdw1 commented Jul 12, 2013

I don't think the issue exists in core modules, I can't think of any that have mass actions via ajax. I've ran into it several times writing custom modules for 1.X, would be nice to have a fix for this in the base code.

@mklishevych
Copy link

I believe that the real problem with massaction object is with the next code in class Mage_Backend_Block_Widget_Grid_Massaction_Abstract:

public function getJavaScript()
{
    return " var {$this->getJsObjectName()} = new varienGridMassaction('{$this->getHtmlId()}', "
        . "{$this->getGridJsObjectName()}, '{$this->getSelectedJson()}'"
        . ", '{$this->getFormFieldNameInternal()}', '{$this->getFormFieldName()}');"
        . "{$this->getJsObjectName()}.setItems({$this->getItemsJson()}); "
        . "{$this->getJsObjectName()}.setGridIds('{$this->getGridIdsJson()}');"
        . ($this->getUseAjax() ? "{$this->getJsObjectName()}.setUseAjax(true);" : '')
        . ($this->getUseSelectAll() ? "{$this->getJsObjectName()}.setUseSelectAll(true);" : '')
        . "{$this->getJsObjectName()}.errorText = '{$this->getErrorText()}';";
}

Because of the var keyword, massaction object is not available if you load the content with ajax.

magento-team pushed a commit that referenced this pull request Mar 23, 2015
[South] Sprint 32: Bug fixes
okorshenko pushed a commit that referenced this pull request Nov 5, 2015
[WebDev + Vanilla] Bugfixes
@colinmollenhour colinmollenhour deleted the fix-ajax-grid branch September 29, 2016 16:57
@colinmollenhour colinmollenhour restored the fix-ajax-grid branch September 29, 2016 16:57
@colinmollenhour colinmollenhour deleted the fix-ajax-grid branch September 29, 2016 16:58
YevSent pushed a commit to YevSent/magento2 that referenced this pull request Jun 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants