Parametrizing AjaxGrid

17 views
Skip to first unread message

Igor Foox

unread,
Nov 20, 2006, 11:31:10 AM11/20/06
to turbo...@googlegroups.com
Hi,

I'd like to use an AjaxGrid to display some tabular information
instead of brewing my own widget, but I'm having trouble figuring out
whether it can do what I want, and how.

What I'd like to do is have a page with a selection box and an
AjaxGrid. The selection box gets populated dynamically through AJAX,
and I'd like the AjaxGrid to be redisplayed whenever
a user selects an option from the selection box. For this I need to
somehow pass a parameter to my json refresh method that supplies the
data to the AjaxGrid.

Is it possible to somehow pass a parameter like this? I've seen how
you can set a parameter in the refresh url in the constructor for the
AjaxGrid, but that's not really useful for me here, since I don't
know the parameter value until the user selects an option.

Any help appreciated! :-)
Igor

Igor Foox

unread,
Nov 27, 2006, 2:07:43 PM11/27/06
to turbo...@googlegroups.com


So after a whole bunch of poking around I figured it out, and I'll
probably be writing it up. Is there any particular place that I can
submit a tutorial on how to use AjaxGrid to the docs?

And also another related question about AjaxGrid. How do I set rows
to be a link, or at the very least hang an 'onclick' action on them?
There seems to be something possible with the 'actions' parameter to
the grid, but it's not trivial to figure out from the code, and I'm
wondering if its use is documented somewhere.

Thanks,
Igor

Diez B. Roggisch

unread,
Nov 27, 2006, 2:50:59 PM11/27/06
to turbo...@googlegroups.com
> So after a whole bunch of poking around I figured it out, and I'll
> probably be writing it up. Is there any particular place that I can
> submit a tutorial on how to use AjaxGrid to the docs?

I guess the Wiki is the appropriate place.

> And also another related question about AjaxGrid. How do I set rows
> to be a link, or at the very least hang an 'onclick' action on them?
> There seems to be something possible with the 'actions' parameter to
> the grid, but it's not trivial to figure out from the code, and I'm
> wondering if its use is documented somewhere.


I do it like this:

import kid


def get_action(rowobject):
return kid.XML("<a href="/whatever?id=%i">edit</a>" % rowobject.id)

You pass that to the columnobject as getter.

Diez

Igor Foox

unread,
Nov 27, 2006, 3:00:47 PM11/27/06
to turbo...@googlegroups.com

I'm a bit confused here, what is columnobject in this instance?

Thanks,
Igor

Diez B. Roggisch

unread,
Nov 27, 2006, 3:29:49 PM11/27/06
to turbo...@googlegroups.com
Igor Foox schrieb:

Argl. I'm sorry, that was targeted towards the DataGrid widget. Sorry
for causing confusion.

But I had a look into the sourcecode - so it appears that one can return
actions to call in the json data. See widget.js - it looks somewhat more
complicated than I can now parse without having a use case on my own.

Diez

Igor Foox

unread,
Nov 27, 2006, 3:37:09 PM11/27/06
to turbo...@googlegroups.com

On 27-Nov-06, at 2:07 PM, Igor Foox wrote:

<snip>

> And also another related question about AjaxGrid. How do I set rows
> to be a link, or at the very least hang an 'onclick' action on
> them? There seems to be something possible with the 'actions'
> parameter to the grid, but it's not trivial to figure out from the
> code, and I'm wondering if its use is documented somewhere.

I've tried doing this by passing an 'actions' parameter to the widget
and I did a little bit farther along but I could only do this by
hacking the ajaxgrid.js file itself.

AjaxGrid.prototype.refresh does an eval() on the parameters it sends
to the server-side refresh method, however
AjaxGrid.prototype.updateGrid doesn't, and just sends the response it
gets to Widget.grid.render.
The problem with this is that Widget.grid.renderRows (called from
Widget.grid.render) does the following:

var actions = Widget.exists(content.actions)? content.actions:{};
...
var p = actions.select.params.concat(row_id);

The problem here is that actions.select.params.concat can't possibly
be a JS function because it's just the stuff returned as JSON from
the server, so this always fails. Similar stuff is done in
Widget.grid.renderRowActionsLink.

The only way I could make this work is by putting this in ajaxgrid.js:
response.actions.select.params.concat = eval
(response.actions.select.params.concat);
which turns it into a function which can then be applied to an
argument. This is obviously not a very good solution because we then
need to check and eval every possible function that we're given in
ajax grid, maybe this logic belongs in the place that calls these
functions?
Or maybe I'm just misunderstanding how I'm supposed to use these
functions, in which case please do correct me. :-)

Igor

Reply all
Reply to author
Forward
0 new messages