replace

....
jQuery(document).ready(function(server_time){jQuery("#%
(id)s").jqGrid({
url:'%(callback)s',
....

with

....
jQuery(document).ready(function(server_time){jQuery("#%
(id)s").jqGrid({
url:'%(callback)s&server_time'+escape(server_time),
....


On Nov 10, 9:34 am, AsmanCom <d.as...@web.de> wrote:
> Hi Massimo, never mind. I do not want the variable passed with
> jQuery.getJSON, but with the url: '% (callback) s', which is called
> with LoadComplete: .trigger ("reload grid").
> Here's the code so far..
>
> _____________________________________________________
> app/models/plugin_jqgrid.py:
>
> def
> plugin_live_grid(table,fieldname=None,fieldvalue=None,col_widths={},
>
> _id=None,columns=None,col_width=80,width=700,height=300):
>     """
>     just do to embed the jqGrid with ajax search capability and
> pagination
>     {{=plugin_jqgrid(db.tablename)}}
>     - table is the db.tablename
>     - fieldname, fieldvalue are an optional filter
> (fieldname==fieldvalue)
>     - _id is the "id" of the DIV that contains the jqGrid
>     - columns is a list of columns names to be displayed
>     - cold_width is the width of each column
>     - height is the height of the jqGrid
>     """
>     from gluon.serializers import json
>     _id = 'jqgrid_%s' % table
>     columns = columns or [x for x in table.fields if
> table[x].readable]
>     colnames = [x.replace('_',' ').capitalize() for x in columns]
>     colmodel = [{'name':x,'index':x,
> 'width':col_widths.get(x,col_width), 'sortable':True} \
>                     for x in columns if table[x].readable]
>     callback = URL(r=request,c='plugin_jqgrid',f='data',
>                    vars=dict(tablename=table._tablename,
>                              columns=','.join(columns),
>                              fieldname=fieldname or '',
>                              fieldvalue=fieldvalue,
>                              ))
>     script="""
> var server_time=null;
> jQuery(document).ready(function(server_time){jQuery("#%
> (id)s").jqGrid({
> url:'%(callback)s',
> datatype: "json",
> colNames: %(colnames)s,
> colModel:%(colmodel)s,
> rowNum:10,
> rowList:[20,50,100],
> pager: '#%(id)s_pager',
> onSelectRow: function(postdata) {web2py_ajax_page('get','/jqgrid2/
> default/tabs2/'+(postdata),null,'panel');},
> loadComplete: function () {
>     var server_time=jQuery("#%(id)s").getGridParam('userData');
>
>     setTimeout(function(){
>      alert(server_time);
>      jQuery("#%(id)s").jqGrid().setGridParam({datatype:"json"});
>      jQuery("#%(id)s").jqGrid().trigger("reloadGrid",
> [{current:true}]);
>
> }, 1000); /* 1000..after 1 seconds */
> },
>
> loadError: function () {
>     setTimeout(function(){
>
>      jQuery("#%(id)s").jqGrid().setGridParam({datatype:"json"});
>      jQuery("#%(id)s").jqGrid().trigger("reloadGrid",
> [{current:true}]);
>
> }, 15000); /* milliseconds (15seconds) */
> },
>
> caption:'%(tablename)s',
> viewrecords: true,
> height:%(height)s,
> loadui:"disabled"});
> jQuery("#%(id)s").jqGrid('navGrid','#%(id)s_pager',
> {search:true,add:false,edit:false,del:false});
> jQuery("#%(id)s").setGridWidth(%(width)s,false);});
> """ % dict(callback=callback,colnames=json(colnames),
> tablename=table._tablename.capitalize(),
>            colmodel=json(colmodel),id=_id,height=height,width=width)
>     return TAG[''](TABLE(_id=_id),
>                    DIV(_id=_id+"_pager"),
>                    SCRIPT(script))
>
> _______________________________________________________
>
> app/controllers/plugin_jqgrid.py:
>
> from random import randint
> from time import sleep
>
> def error():
>     raise HTTP(400)
>
> def data2():# for testing
>     if randint(1,3) == 1:
>         raise HTTP(400)
>     else:
>         return data2()
>
> def data():
>     sleep(10) # for testing
>     "http://trirand.com/blog/jqgrid/server.php?
> q=1&_search=false&nd=1267835445772&rows=10&page=1&sidx=amount&sord=asc&searchField=&searchString=&searchOper="
>     from gluon.serializers import json
>     import cgi
>     tablename = request.vars.tablename or error()
>     columns = (request.vars.columns or error()).split(',')
>     rows=int(request.vars.rows or 25)
>     page=int(request.vars.page or 0)
>     sidx=request.vars.sidx or 'id'
>     sord=request.vars.sord or 'asc'
>     searchField=request.vars.searchField
>     searchString=request.vars.searchString
>     searchOper={'eq':lambda a,b: a==b,
>                 'nq':lambda a,b: a!=b,
>                 'gt':lambda a,b: a>b,
>                 'ge':lambda a,b: a>=b,
>                 'lt':lambda a,b: a<b,
>                 'le':lambda a,b: a<=b,
>                 'bw':lambda a,b: a.like(b+'%'),
>                 'bn':lambda a,b: ~a.like(b+'%'),
>                 'ew':lambda a,b: a.like('%'+b),
>                 'en':lambda a,b: ~a.like('%'+b),
>                 'cn':lambda a,b: a.like('%'+b+'%'),
>                 'nc':lambda a,b: ~a.like('%'+b+'%'),
>                 'in':lambda a,b: a.belongs(b.split()),
>                 'ni':lambda a,b: ~a.belongs(b.split())}\
>                 [request.vars.searchOper or 'eq']
>     table=db[tablename]
>     if request.vars.fieldname:
>         dbset =
> table._db(table[request.vars.fieldname]==request.vars.fieldvalue)
>     else:
>         dbset = table._db(table.id>0)
>     if searchField:
> dbset=dbset(searchOper(table[searchField],searchString))
>     orderby = table[sidx]
>     if sord=='desc': orderby=~orderby
>     limitby=(rows*(page-1),rows*page)
>     fields = [table[f] for f in columns]
>     records = dbset.select(orderby=orderby,limitby=limitby,*fields)
>     nrecords = dbset.count()
>     items = {}
>     items['userdata']=request.now
>     items['page']=page
>     items['total']=int((nrecords+(rows-1))/rows)
>     items['records']=nrecords
>     readable_fields=[f.name for f in fields if f.readable]
>     def f(value,fieldname):
>         r = table[fieldname].represent
>         if r: value=r(value)
>         try: return value.xml()
>         except: return cgi.escape(str(value))
>
>     items['rows']=[{'id':r.id,'cell':[f(r[x],x) for x in
> readable_fields]} \
>                        for r in records]
>     return json(items)
> ________________________________________
>
> app/controllers/default.py:
>
> # -*- coding: utf-8 -*-
>
> #########################################################################
> ## This is a samples controller
> ## - index is the default action of any application
> ## - user is required for authentication and authorization
> ## - download is for downloading files uploaded in the db (does
> streaming)
> ## - call exposes all registered services (none by default)
> #########################################################################
>
> def index():
>     """
>     example action using the internationalization operator T and flash
>     rendered by views/default/index.html or views/generic.html
>     """
>     response.flash = T('Welcome to web2py')
>     return dict(message=T('Hello World'))
>
> def user():
>     """
>     exposes:
>    http://..../[app]/default/user/login
>    http://..../[app]/default/user/logout
>    http://..../[app]/default/user/register
>    http://..../[app]/default/user/profile
>    http://..../[app]/default/user/retrieve_password
>    http://..../[app]/default/user/change_password
>     use @auth.requires_login()
>         @auth.requires_membership('group name')
>         @auth.requires_permission('read','table name',record_id)
>     to decorate functions that need access control
>     """
>     return dict(form=auth())
>
> def download():
>     """
>     allows downloading of uploaded files
>    http://..../[app]/default/download/[filename]
>     """
>     return response.download(request,db)
>
> def call():
>     """
>     exposes services. for example:
>    http://..../[app]/default/call/jsonrpc
>     decorate with @services.jsonrpc the functions to expose
>     supports xml, json, xmlrpc, jsonrpc, amfrpc, rss, csv
>     """
>     session.forget()
>     return service()
>
> def jqgrid():
>     """
>     exposes services. for example:
>    http://..../[app]/default/call/jsonrpc
>     decorate with @services.jsonrpc the functions to expose
>     supports xml, json, xmlrpc, jsonrpc, amfrpc, rss, csv
>     """
>     return dict(grid=plugin_live_grid(db.device))
>
> _________________________________
>
> THX
>
> Dieter Asman
>
> On 10 Nov., 15:37, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > Sorry I did not help. I cannot help you because the code you have
> > above is incomplete. It opens a """ but never closes so I not
> > understand how callback is used. Anyway I assume in the view you have:
>
> > {{callback = URL(r=request,c='plugin_jqgrid',f='data',
> >                    vars=dict(tablename=table._tablename,
> >                              columns=','.join(columns),
> >                              fieldname=fieldname or '',
> >                              fieldvalue=fieldvalue,
> >                              ))}}
>
> > var server_time="test"
>
> > ... jQuery.getJSON('{{=callback}}
> > &'server_time='+escape(server_time)) ...
>
> > hope this helps.
>
> > On Nov 10, 8:24 am, AsmanCom <d.as...@web.de> wrote:
>
> > > Is there no solution to my concerns?
>
> > > It´s such a pity...
>
>

Reply via email to