I'm trying to think of ways to do it, and I'm coming up pretty short. My
main reason is because, with SQLAlchemy at least, you're not *actually*
getting a list of rows, not unless you're using the .all() method on your
query. Since many people don't do that (I know I don't, and I suspect most
others don't due to memory concerns), that means there's no actual record
of the results.

What you get from SA, by the way, is an iterator that will be exhausted by
the time you try to use it elsewhere.

Next, add in some advanced work with the datagrid (and some nifty
javascript), and the result is that what is seen in the user's browser
could have very little bearing on the result set that was passed in from
the server. You really do have to read the grid that's being displayed. Not
even work with the results passed back, but actually read the cells as they
are shown. It's the only option that I see that works.

>From there, you can pass the data from the browser back to a rendering
method that creates whatever data format you want to return.

I'm sorry, I just don't see a better option. Maybe someone else does, but I
sure don't.

On Fri, Nov 11, 2011 at 3:08 PM, Sean DiZazzo <[email protected]>wrote:

> > I'm trying to make a generic widget that can export whatever records
> > are being shown in a DataGrid.  I have the code to generate the file
> > and to serve it up to the user using cherrypy, but I'm brain farting
> > on how to pass the records in to the widget.  I want to just be able
> > to pass them in via the template like you do with a datagrid.  ie $
> > {export_records(records).display()}.
> >
>
> Hi again.  I'm looking at this issue again today, and am no closer to
> a solution.  I have no problem serving up the file.  I plan to format
> the data into a string in a controller method and then call:
>
> pylons.response.headers['Content-Type'] = 'application/vnd.ms-excel;'
> # or 'application/pdf', etc
> pylons.response.headers['Content-Disposition']
> ='attachment;filename=export.xls'
>
> and then return the string.  This serves up the file nicely.
>
> My problem is that I would like to have a generic button that will
> work with any data that is currently being displayed in the grid.  The
> data presented in the grid might have been filtered, and I don't want
> to have to keep track of the filter terms and pass them in to the
> export widget so it can generate the same list of records...I just
> want to pass the same list used to populate the grid widget in to the
> export widget and have it available in the defined action controller
> method.  Then I would use it to format the file and serve it up.
>
> Is this possible?  Can someone give me some pointers on how to do
> this?  Am I missing something obvious?  Should I be looking at
> creating a widget?
>
> I have a hard time visualizing it, but something makes me think I
> would have to store all of the data as json (or something) as a hidden
> field in the export button form... hopefully I'm way off.  :)
>
> Thanks in advance.
>
> ~Sean
>
> --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/turbogears?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to