It is not possible to properly load an ui component in a popin content loaded in ajax. On a standard page it works well, but as a ajax result, it won't.
<div data-bind="scope:'myComponent'" data-mage-init='
{
"Magento_Ui/js/core/app": {
"components": {
"myComponent": {
"component": "My_Module/js/my-component"
}
}
}
}
'>
<!-- ko template: getTemplate() --><!-- /ko -->
</div>
$.ajax(this.url)
.done(
function(data) {
this.modalContainer.html(data);
this.modalContainer.trigger('contentUpdated');
}
);
data-mage-init part should be remove from the DOM and interpreted, and my component should appear in my popin.data-mage-init part should is removed, but my component container stay empty.<!-- ko template: getTemplate() --><!-- /ko --> doesn't seem to be interpreted.having this issue in 2.1.8 any resolution yet?
Hi, it is happen because in UiRegistry already exist data of Ui Component, try to clear Ui Registry, and reinit Ui Component. Something like that
$('.yourSelector').click(function () {
uiRegistry.remove(scopeName);
$.ajax({
url: url,
success: function (response) {
$('.main').replaceWith($(response).find('.main'));
$('.main').trigger('contentUpdated'); //reinit your Ui Component
$('.main').applyBindings(); //apply new data
}
})
}
Hi @Pigau
Could you please let us know if the issue is still actual? Thank you
@Pigau, we are closing this issue due to inactivity. If you'd like to update it, please reopen the issue.
Hi ,I am also facing the same issue.Want to reload the ui component grid in poup
Hi, it is happen because in UiRegistry already exist data of Ui Component, try to clear Ui Registry, and reinit Ui Component. Something like that
$('.yourSelector').click(function () { uiRegistry.remove(scopeName); $.ajax({ url: url, success: function (response) { $('.main').replaceWith($(response).find('.main')); $('.main').trigger('contentUpdated'); //reinit your Ui Component $('.main').applyBindings(); //apply new data } }) }
Thank you so much.
Hi, it is happen because in UiRegistry already exist data of Ui Component, try to clear Ui Registry, and reinit Ui Component. Something like that
$('.yourSelector').click(function () { uiRegistry.remove(scopeName); $.ajax({ url: url, success: function (response) { $('.main').replaceWith($(response).find('.main')); $('.main').trigger('contentUpdated'); //reinit your Ui Component $('.main').applyBindings(); //apply new data } }) }
Can you maybe explain this a bit better for me i'm trying something similar however having great difficulty, I asked a question https://magento.stackexchange.com/questions/275656/load-a-ui-component-with-ajax-within-admin-tab however not had much luck and hoping it is a simple fix like yours.
@danilkrasnorudskyi Thanks! It works for me.
*.html:
<div id="own_image" data-bind="scope:'own_image'">
<!-- ko template: getTemplate() --><!-- /ko -->
</div>
*.js:
initialize: function () {
this._super();
$('#' + this.name).applyBindings();
},
Most helpful comment
Hi, it is happen because in UiRegistry already exist data of Ui Component, try to clear Ui Registry, and reinit Ui Component. Something like that
$('.yourSelector').click(function () { uiRegistry.remove(scopeName); $.ajax({ url: url, success: function (response) { $('.main').replaceWith($(response).find('.main')); $('.main').trigger('contentUpdated'); //reinit your Ui Component $('.main').applyBindings(); //apply new data } }) }