Is Jquery $(this) broken by jqgrid gridunload method?

Posted by chohi on Stack Overflow See other posts from Stack Overflow or by chohi
Published on 2012-04-04T03:14:39Z Indexed on 2012/04/04 5:29 UTC
Read the original article Hit count: 228

Filed under:
|
|

I expect the following code to unload a javascipt jqgrid, then load another grid with different options, including different columns

//onload
(function($)
$.fn.myGridFn = function(options){
   $(this).jqGrid('GridUnload');
   $(this).jqGrid(options.gridoptions);


//....

$('#select').change(function(){ 
    switch($(this).val())
    {
      case 'grid1':
            $('#grid').myGridFn({gridoptions:{/*grid1 options*/}});
            break;
      case 'grid2':
            $('#grid').myGridFn({gridoptions:{/*grid2 options*/}});
            break;
    }
   });


})(jQuery);

//...
<table id="grid"></table>

What I get is the grid unloading, then I have to change the selection in the select element and back again to load the new grid.

Updated: If I replace the $(this) in the plugin with the actual element selector $('#grid') - it works just fine, I cant do this in my real app because the plugin is used by several other table elements and grids

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery