Featured post
Can I change the double click event handler (ondblClickRow) for a jQuery jqGrid plug-in after it has been rendered in ASP.NET MVC? -
i have been using jqgrid success; however, i've hit can't seem working. returning grid definition partialviewresult
via ajax , appending the results div.
i change double click event said grid. i'm using firebug , can seem grid element using $('#my-grid')[0]
when attempt call methods on below tells me jqgrid "not defined".
i'm pretty sure i've got jqgrid stuff referenced correctly or wouldn't have gotten far (i have been displaying , editting data in grids already). here's code gets , attempts modify grid definition:
$(document).ready(function() { //add grid pulling via ajax $.get('<%=url.action("grid","entity", new {id = "customeraccount"}) %>', function(htmlresult) { //append grid definition div $('#customer-list').append(htmlresult); var mygrid = $($('#customeraccount-grid')[0]); $(mygrid).jqgrid('setgridparam', { ondblclickrow: function(rowid, irow, icol, e) { console.log('dblclicked'); } }) .trigger('reloadgrid'); //note: i've tried , without reloadgrid }
update: think i've come conclusion sure i'm referencing element jquery object there timing issue. simplified load of grid definition below illustrates issue:
//append grid definition div $('#customer-list').load('<%=url.action("grid","entity", new {id = "customeraccount"}) %>',function() { console.log('sortname=' + $($('#customeraccount-grid:first')).jqgrid('getgridparam', 'sortname')); });
this logs sortname=undefined; however, if copy , paste same line firebug displays sortname=name, correct.
final update: big part of problem may have been not getting element jquery object crediting drachenstern solution (thanks!) but, once beyond reason event handler still not being wired because grid definition being retrieved via ajax , did not exist when attempted bind ondblclickrow. solution simple: merely added async: false grid definition call know definition there before additiona event handlers etc bound. retrieving grid definition via ajax because building grids dynamically on server side of asp.net mvc app. still retrieving data for grid asynchonously. works great now.
var mygrid = $('#my-grid')[0];
this code sets mygrid dom element. other dom elements be:
<a>, <div>, <input>, <body>, <table>, etc
there no native dom property .jqgrid
. perhaps meant first child, keep in jquery wrapper? there several options, depending on readability want. http://api.jquery.com/first/ allows use chaining , looks neater, , may more performant given case. there's also:
var mygrid = $( $('#my-grid')[0] );
or alternately:
$(mygrid).jqgrid('setgridparam',{ ondblclickrow: function(){console.log('hello');}});
and of course introduce middle element:
var mygridtemp = $('#my-grid')[0]; var mygrid = $( mygridtemp ); mygrid.jqgrid('setgridparam',{ ondblclickrow: function(){console.log('hello');}});
but primary problem first line of example gives dom element, not jquery element.
- Get link
- X
- Other Apps
Comments
Post a Comment