Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

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.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -