The problem is that the 'selection' form isn't being resubmitted
therefore its values aren't available in the request object on
subsequent calls to your controller method. What I've done in the past
is to save the 'selection' form values to cookies (or possibly the
session object) whenever they change (a submit of the selection form)
and then whenever the page is redisplayed, re-populate the selection for
with the values from the cookies.
The unfortunate side-effect of this method is that the next time you
come to this form within the same session your old values will populate
into the form. I've overcome this with a crude hack to pass a parm on
the URL to tell me to ignore my remembered values in that case.
I'm hoping someone tells me that this method is dumb and can suggest a
better way, but at this point, this is how I would handle it.
-Jim
On 12/16/2011 8:31 AM, Cliff wrote:
Do you get a 'No records found' message, or is the data table
completely gone?
On Dec 16, 4:33 am, JmiXIII<[email protected]> wrote:
I have a problem using SQLFORM.grid and a query from a FORM:
Here is my controller
def synthese():
ListeFamille=db(db.ATPOSTE.id>0).select(orderby=db.ATPOSTE.PS_FAMI)
selection=FORM(TABLE(TR(
TD('Début',INPUT(_name='Deb',id="1",_class="date", requires
= IS_DATE(error_message=T('Doit être de la forme AAAA-MM-JJ !')))),
TD('Fin',INPUT(_name='Fin',id="2",_class="date", requires =
IS_DATE(error_message=T('Doit être de la forme AAAA-MM-JJ !')))),
TD('Famille',SELECT('Frappe','Reprise','Tri',_name='Famille')),
TD(INPUT(_type='submit',_value='Sélectionner'))
)))
Deb=request.vars.Deb
Fin=request.vars.Fin
Famille=request.vars.Famille
if Deb:
query1=db.Rebuts.Date>=Deb
else: query1=db.Rebuts.id>0
if Fin:
query2=db.Rebuts.Date<=Fin
else: query2=db.Rebuts.id>0
query3=db.Rebuts.Famille==Famille
if Famille=='Tri' :
query3=(db.Rebuts.Machine=='TRI')&(db.Rebuts.Famille=='NQ')
if Famille=='Reprise' :
query3=(db.Rebuts.Famille!='NQ')&(db.Rebuts.Famille!='Frappe')
query=query1&query2&query3
records=db(query).select()
if selection.accepts(request.vars,keepvalues=True):
pass
form=SQLFORM.grid(query=query,user_signature=False,searchable=True,paginate
=True)
And the return dict (form=form)
The query works well and the grid also when I fill Selection and validate.
Yet when I paginate, sort or query inside teh grid I lost every my grid
data (empty grid).
Does somebody knows what's wrong with my controller ?
Thanks a lot to web2py fantastic community
JmiXIII