is there any requirejs integration magento2 uses it and I really dislike everything about it but I have to use it for this client. I just keep phpgrid out of the requirejs, the only problem is that there’s no way to delay jQuery being called on load with phpgrid, and any hooks I write to make jquery global aren’t ready yet because requirejs is slow. I’d need a way to delay the jQuery calls of phpgrid at all until I choose to fire them. Simply having jQuery load from a script tag breaks other modules that use requirejs and jquery on the page because requirejs should never be used by anyone for any reason.
Hello,
I’ve not tested it with requriejs. Give me some time and i’ll update you back.
One solution could be to move all initialization JS code inside a function and call it when you need.
Edit lib/inc/jqgrid_dist.php
Find this code segment:
< script >
var phpgrid = jQuery(“#<?php echo $grid_id?>”);
var phpgrid_pager = jQuery(“#<?php echo $grid_id.”_pager”?>”);
var fx_ajax_file_upload;
var fx_replace_upload;
…..
jQuery(document).ready(function(){
<?php echo $this->render_js($grid_id,$out);?>
});
< /script >
and then wrap it in a funciton, e.g.
< script >
function phpgrid_init()
{
var phpgrid = jQuery(“#<?php echo $grid_id?>”);
var phpgrid_pager = jQuery(“#<?php echo $grid_id.”_pager”?>”);
var fx_ajax_file_upload;
var fx_replace_upload;
…..
jQuery(document).ready(function(){
<?php echo $this->render_js($grid_id,$out);?>
});
}
< /script >
This way, grid will not call any jQuery code until you call phpgrid_init() function.
Hope it helps.
A little correction, to make phpgrid global JS available, you need to move function vars outside phpgrid_init() declaration.
— script start —
var fx_ajax_file_upload;
var fx_replace_upload;
var fx_bulk_update;
var fx_bulk_unrequire;
var fx_get_dropdown;
var fx_reload_dropdown;
var fx_grid_resize;
var fx_show_form;
var fx_tooltip_init;
var fx_show_view_dialog;
function phpgrid_init()
{
var phpgrid = jQuery(“#<?php echo $grid_id?>”);
var phpgrid_pager = jQuery(“#<?php echo $grid_id.”_pager”?>”);
…
jQuery(document).ready(function(){
<?php echo $this->render_js($grid_id,$out);?>
});
}
— script end —
Also declare this var outside phpgrid_init:
var fx_tooltip_init;
and replace:
function fx_tooltip_init()
with:
fx_tooltip_init = function ()
Just wanted to know if your issue is solved?
Your code worked I just had to deal with caching.
I got it to load error free but it was a nightmare for something that would have been braindead simple and no extra work otherwise. Screw requirejs.
require.config({
paths: {
//’jqjquery’: ‘/phpgrid/lib/js/jquery.min’,
‘grid-en’: ‘/phpgrid/lib/js/jqgrid/js/i18n/grid.locale-en’,
‘jqgrid’: ‘/phpgrid/lib/js/jqgrid/js/jquery.jqGrid.min’,
‘jq-ui’: ‘/phpgrid/lib/js/themes/jquery-ui.custom.min’,
},
shim: {
/*’jqjquery’: {
exports:’jquery’
},*/
‘grid-en’: {
deps:[‘jquery’]
},
‘jqgrid’: {
deps:[‘jquery’]
},
‘jq-ui’: {
deps:[‘jquery’]
}
}
});
require([‘jquery’,’grid-en’,’jqgrid’,’jq-ui’], function(jQuery) {
window.$ = jQuery;
window.jQuery = jQuery;
phpgrid_init();
jQuery(document).ready(dobinds);
});