Hi Craig,

With regard to the tw2.jqplugins.jqgrid specifically, there are two 
parameters 
passed to `options` which need to be controlled:  'url' & 'editurl', the 
former
for the json data request, the latter being used to control add/edit & 
delete
events fired by the respective buttons on the the jqgrid's nav bar.

To start with the former, options= {'url': '/data_request/'} requires a 
corresponding controller, something along the lines of: 

@expose('json')
@validate(validators=[some_validator])
def data_request(self, page=1, rows=30, sidx=1, sord='asc', _search='false',
                    searchOper=u'', searchField=u'', searchString=u'', 
**kw):
                    
    qry = DBSession.query()
    qry.filter()         # based on searchField
    
    qry = qry.order_by() # based on sidx/sord

    offset = (page-1) * rows
    qry = qry.offset(offset).limit(rows)
 
    records = [{'id': rw.id),
                'cell': [ rw.x, rw.y , rw.z ]} for rw in qry]
 
    total = int(ceil(result_count / float(rows)))
 
    return dict(page=page, total=total, records=result_count, rows=records)
 
 
The limit/offset (as specified by the `page` & `rows` means that the 
'thousands 
of rows' you mentioned aren't returned. 
 
(note: using a formencode validation schema in the @validate is very useful 
as 
this will deal with string to python-type conversion for you before the 
controller's hit.)

Add/edit/delete functionality is dealt with by options = {'editurl': 
'/myediturl/'}
And would require a controller that looks something like...

@expose('json')
def myediturl(self, oper, **kw):
    if oper == 'add':
        ... do stuff ...

    elif oper == 'edit':
        ... do stuff ...

    elif oper == 'del':
        ... do stuff ...
        
    return dict() 
        
        
Hope that helps!

Rob



Am Mittwoch, 18. Juli 2012 23:01:12 UTC+1 schrieb Craig Small:
>
> Hi, 
>   There are muliple tutorials out there showing how toscawidgets works 
> with turbogears but often they are contradicting in how they come about 
> it. A good example is some use the middlewear, some use a specific 
> call (eg a data routine) and then others bring up the data in the 
> actual function that generates the grid. 
>
> I'm specifically interesting in the jqgrid setup where the grid is 
> displayed once and it then makes calls to get specific data using, i 
> guess a json transfer happens there. Also I've not seen how the query 
> does sensible limiting either; what i mean is if you have several 
> thousand records you dont want to load them all in and then ditch 
> most to display the middle 10. I couldn't see how that was done. 
>
> I've 2.2.0rc2 here on my projects and they seem to be going ok. 
>
>  - Craig 
> -- 
> Craig Small VK2XLZ   http://enc.com.au/          csmall at : enc.com.au 
> Debian GNU/Linux     http://www.debian.org/      csmall at : debian.org 
> GPG fingerprint:     5D2F B320 B825 D939 04D2  0519 3938 F96B DF50 FEA5 
>

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/turbogears/-/5U1dUrLUHy4J.
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