Magento 2: отображать загрузчик во время вызова Ajax в действии строки столбца?

Столбец сетки xml:

<column name='actions' class='My\Test\Ui\Component\Listing\Columns\Feeds\AdvancedActions'> 
    <argument name='data' xsi:type='array'> 
        <item name='config' xsi:type='array'>
            <item name='component' xsi:type='string'>My_Test/js/grid/columns/actions</item> 
            <item name='dataType' xsi:type='string'>text</item> 
            <item name='label' xsi:type='string' translate='true'>Actions</item> 
            <item name='sortOrder' xsi:type='number'>90</item> 
        </item>
    </argument>
</column>

Действия.js

define(
    [
    'jquery',
    'underscore',
    'mageUtils',
    'uiRegistry',
    'Magento_Ui/js/grid/columns/actions',
    'Magento_Ui/js/modal/confirm'
    ], function ($, _, utils, registry, Column, confirm) {
        'use strict';
    return Column.extend(
        {

            /**
             * Applies specified action.
             *
             * @param   {String} actionIndex - Actions' identifier.
             * @param   {Number} rowIndex - Index of a row.
             * @returns {ActionsColumn} Chainable.
             */
            applyAction: function (actionIndex, rowIndex) {
                var action = this.getAction(rowIndex, actionIndex),
                callback = this._getCallback(action);

                if (action.confirm) {
                    this._confirm(action, callback);
                } else if (action.popup) {
                    this._popup(action, callback);
                } else {
                    callback();
                }

                return this;
            },


           _popup: function (action, callback) {
                var popupData = action.popup;
                var dataType = popupData.type;

                //Start loader
                var body = $('body').loader();
                body.loader('show');

                if (popupData.file !== undefined && popupData.file !== '') {
                    $.ajax(
                        {
                            url: popupData.file,
                            async: false,
                            dataType: "text",
                            type: 'GET',
                            showLoader: true, //use for display loader
                            success: function (data) {
                                popupData.message = data;
                            }
                        }
                    );
                }
                //Stop loader
                body.loader('hide');
            },
});

Использовались showLoader: true и var body = $('body').loader(); body.loader('show');, но не удалось запустить загрузчик во время запроса ajax.

Нужна альтернатива для запуска загрузчика во время вызова ajax.


person Milind Singh    schedule 10.08.2018    source источник


Ответы (4)


Я столкнулся с той же проблемой. В моем случае мне нужно загрузить зависимость 'jquery/ui'.

define(
    [
    'jquery',
    ...
    'jquery/ui'
person Khoa TruongDinh    schedule 06.03.2019
comment
Попробуйте очистить кеш и поставить jquery/ui в качестве последней зависимости. - person Khoa TruongDinh; 06.03.2019
comment
Пробовал, но та же проблема. - person Milind Singh; 06.03.2019

Пожалуйста, взгляните на приведенный ниже код, который может помочь.

define([
    'jquery',
    'Magento_Checkout/js/model/full-screen-loader',
], function ($,fullScreenLoader
) {
    //Start Loader
    fullScreenLoader.startLoader();
    //Your AJax COde here

    //Stop Loader
    fullScreenLoader.stopLoader();
});
person Sanjib Chowdhury    schedule 14.11.2019

Просто добавьте зависимость loader в конец:

define([
    'jquery',
    ...
    'loader'
]

showLoader: true и var body = $('body'); body.loader('hide'); начнут работать.

person Anton Suslov    schedule 12.12.2019

Попробуйте $('body').trigger('processStart') и $('body').trigger('processStop')

person Yogesh Agarwal    schedule 05.05.2020