[web2py] jqgrid onSelectRow refresh iframe

564 views
Skip to first unread message

Jason Lotz

unread,
May 14, 2010, 3:59:26 AM5/14/10
to web2py-users
Now I have two containers, one includes jqgrid_plugin the other
includes iframe to display /default/details view. Both work fine on
the initial load of the page. Using jqgrid onSelectRow event I tried
to add a function to update the iframe page.

## View
<div>
{{=plugin_jqgrid(db.test,columns=['fields'],height=200)}}
</div>
<div>
<iframe id="myframe" src="{{=URL(r=request,f='details',args=2)}}"></
iframe>
</div>

## model
jQuery(document).ready(function(){
jQuery("#%(id)s").jqGrid({ onSelectRow: function() {$
('#myframe').attr('src',"{{=URL(r=request,f='details',args=2)}}");}
});

However when a row is selected the iframe returns Invalid Request.
It's not even calling the controller, just displays Invalid Request. I
haven't quite figured out how to get jqgrid and the server
communicating. I've been able to show grid values using alert and get
jquery to handle data sent from server but can't get jqgrid to trigger
the server and the server read jqgrid.Parameters.

Any suggestions as to the best way to update iframe contents by
selecting a row? And/Or someone kindly provide some sort of
explanation how jquery and server communicate would be greatly
appreciated !!..


Jay

Jason Lotz

unread,
May 14, 2010, 4:58:24 AM5/14/10
to web2py-users
The first and obvious thing I see I did wrong was trying to put python
into jquery script.

jQuery("#%(id)s").jqGrid({ onSelectRow: function() {
$
('#myframe').attr('src',"{{=URL(r=request,f='details',args=2)}}");}

But I still don't understand how I can make it dynamic src, or how to
get jquery to communicate with the server.


Jay

Jason Lotz

unread,
May 14, 2010, 5:32:23 AM5/14/10
to web2py-users
Sorry to keep replying to myself. Just wanted to let you know my
progress. After stepping back and evaluating the case I managed to
configure it as I wanted.

## View
jQuery(document).ready(function(){jQuery("#%(id)s").jqGrid({
onSelectRow: function(postdata){$("#myframe").attr('src',"/MyApp/
default/details/"+(postdata));}
});


## Controller
def details():
id = request.args[0]
// everything else
return dict()


Jay

AsmanCom

unread,
May 14, 2010, 10:26:56 AM5/14/10
to web2py-users
Hi,

i am working with JQGrid plugin too.
Just to get your approach right.. you´ve realised a Master-Detail
function with the JQGrid?
Very nice! May i can use this too.

Is the code(for Controller, View) from your last post working, right
now?
Did you made any changes to the ##model code?

I am trying to implemented the "Subgrid" feature:
http://www.trirand.com/blog/jqgrid/jqgrid.html ->"New since beta 3.0"
->"subgrid with JSON Data"

This could be a nice feature, and also it would be cool to let the
grid show Images from the "upload" Field.

Dieter Asman

Jason Lotz

unread,
May 15, 2010, 5:42:59 AM5/15/10
to web2py-users
Yes I got it working. Using the jqgrid_plugin, very nicely prepared by
parroit, I added an onSelectRow event to trigger the reload of an
iframe on the same page. The id of the selected row is posted as args
to the url. The controller function then uses the row_id to update the
view shown in the iframe.

Same concept as the Subgrid feature show in demo by jqgrid. Instead of
adding the details of the master grid to a subgrid I'm showing the
details in a formatted view page located in an iframe so the details
can be updated (as the rows are selected) without having to refresh
the whole page.


Jay
> > > > includesiframeto display /default/details view. Both work fine on
> > > > the initial load of the page. Using jqgrid onSelectRow event I tried
> > > > to add a function to update theiframepage.
>
> > > > ## View
> > > > <div>
> > > >    {{=plugin_jqgrid(db.test,columns=['fields'],height=200)}}
> > > > </div>
> > > > <div>
> > > >    <iframeid="myframe" src="{{=URL(r=request,f='details',args=2)}}"></
> > > >iframe>
> > > > </div>
>
> > > > ## model
> > > > jQuery(document).ready(function(){
> > > >    jQuery("#%(id)s").jqGrid({ onSelectRow: function() {$
> > > > ('#myframe').attr('src',"{{=URL(r=request,f='details',args=2)}}");}
>
> > > > });
>
> > > > However when a row is selected theiframereturns Invalid Request.
> > > > It's not even calling the controller, just displays Invalid Request. I
> > > > haven't quite figured out how to get jqgrid and the server
> > > > communicating. I've been able to show grid values using alert and get
> > > > jquery to handle data sent from server but can't get jqgrid to trigger
> > > > the server and the server read jqgrid.Parameters.
>
> > > > Any suggestions as to the best way to updateiframecontents by

Jason Lotz

unread,
May 15, 2010, 5:44:15 AM5/15/10
to web2py-users
Reply all
Reply to author
Forward
0 new messages