[web2py] Re: SQLFORM.grid pagination refresh
ok so this is what I have for the view script $('#input4').keyup(function(){ input_value = $(#input4).val(); web2py_component('{{=URL(default, ajaxTable3.load)}}' + '?count=' + input_value, 'grid'); }); /script and this is the controller function def ajaxTable3(): query = (db.applicant.id 0) (db.applicant.id request.vars.count') grid = SQLFORM.grid(query, searchable=False, csv=False) return grid now if I replace request.vars.count with just a number, like say 60 the page works fine and it pulls the records, and no problem with the pagination but with request.vars.count, when I click the pagination, I get this error -- type 'exceptions.RuntimeError' Cannot compare applicant.id None which I think is because of request.vars.count is not set when the pagination is clicked I guess? --
Re: [web2py] Re: SQLFORM.grid pagination refresh
query = (db.applicant.id 0) (db.applicant.id (request.vars.count or 60)') On Wed, Jul 25, 2012 at 5:13 PM, dave arifu...@gmail.com wrote: ok so this is what I have for the view script $('#input4').keyup(function(){ input_value = $(#input4).val(); web2py_component('{{=URL(default, ajaxTable3.load)}}' + '?count=' + input_value, 'grid'); }); /script and this is the controller function def ajaxTable3(): query = (db.applicant.id 0) (db.applicant.id request.vars.count') grid = SQLFORM.grid(query, searchable=False, csv=False) return grid now if I replace request.vars.count with just a number, like say 60 the page works fine and it pulls the records, and no problem with the pagination but with request.vars.count, when I click the pagination, I get this error -- type 'exceptions.RuntimeError' Cannot compare applicant.id None which I think is because of request.vars.count is not set when the pagination is clicked I guess? -- --
Re: [web2py] Re: SQLFORM.grid pagination refresh
I actually dont want 60, I just gave that as an example --
[web2py] Re: SQLFORM.grid pagination refresh
Yeah, it looks like the query string isn't propagated to the links within the table. However, you can propagate URL args by specifying the args argument to .grid(). Maybe something like this: {{=LOAD('default', 'ajaxTable2.load', args=[60], ajax=True, target='grid')}} script $('#input4').keyup(function(){ input_value = $(#input4).val(); web2py_component('{{=URL(default, ajaxTable3.load)}}' + '/' +input_value , 'grid'); }); /script def ajaxTable3(): query = (db.applicant.id 0) (db.applicant.id request.args(0)) grid = SQLFORM.grid(query, args=[request.args(0)], searchable=False, csv =False) return grid Also, do not put the {{=LOAD(...)}} inside a div with id=grid. The LOAD() helper automatically creates its own div with the id set to the target argument (if target isn't specified, it generates a random id automatically). Anthony --
[web2py] Re: SQLFORM.grid pagination refresh
Thank you very much this solved the problem, very nice people around, I guess im sticking to web2yp for my framework of choice --
[web2py] Re: SQLFORM.grid pagination refresh
:-) On Wednesday, July 25, 2012 8:41:42 PM UTC-4, dave wrote: Thank you very much this solved the problem, very nice people around, I guess im sticking to web2yp for my framework of choice --
[web2py] Re: SQLFORM.grid pagination refresh
The problem is when I filter using input boxes from outside, I need to use the ajax function from the view, like input name=id4 type=text class=input-small id=input4 value=40 onkeyup=ajax('ajaxTable3', ['id4'], 'grid') / , and I do replace the load function which is inside the div grid div id = grid {{=LOAD('default','ajaxTable2.load',ajax=True, target='grid', content='loading...')}} /div when the first page loads, the links will be trapped, but after the keyup fires, the div id grid is replaced by the ajax function, is there another way to go about this problem, I tried everything including your solution above, but when I click the pagination links the page loads by itself --
[web2py] Re: SQLFORM.grid pagination refresh
Then don't use the ajax() function. Instead, create a jQuery event handler to capture the keyup event. Then, in the handler, grab the input value and refresh the component by calling: web2py_component('{{=URL(default, ajaxTable2.load)}}' + '?count=' +input_value , 'grid') In that case, the input value will be available as request.vars.count in the ajaxTable2 function. Anthony On Wednesday, July 25, 2012 12:40:29 AM UTC-4, dave wrote: The problem is when I filter using input boxes from outside, I need to use the ajax function from the view, like input name=id4 type=text class=input-small id=input4 value=40 onkeyup=ajax('ajaxTable3', ['id4'], 'grid') / , and I do replace the load function which is inside the div grid div id = grid {{=LOAD('default','ajaxTable2.load',ajax=True, target='grid', content='loading...')}} /div when the first page loads, the links will be trapped, but after the keyup fires, the div id grid is replaced by the ajax function, is there another way to go about this problem, I tried everything including your solution above, but when I click the pagination links the page loads by itself --
[web2py] Re: SQLFORM.grid pagination refresh
When you submit a form in an Ajax component, only the component will refresh -- so if you make a filter form contained in the component with the grid, when the form is submitted, it will reload the whole component. You can also customize the grid search widget to do whatever you want -- both searchable and search_widget take callables, so you can customize the search behavior. Finally, even if your filter form/widget is outside the grid component, you can use JS to trigger a reload of the component by calling the web2py_component() JS function directly. Anthony On Sunday, July 22, 2012 11:47:13 PM UTC-4, dave wrote: Wow, that was fast, first time asker here, I have an SQLFORM.grid in a view, when I click the pagination links at the bottom of the page 1, 2, 3 etc, the whole page refreshes. To avoid this problem, I created a component and put it in a view div id=grid {{=LOAD('default','ajaxTable2.load',ajax=True, target='grid', content='loading...')}} /div https://lh5.googleusercontent.com/-IuP9zYl2i3E/UAzI4jmSzaI/CrA/tjLj4mSDifA/s1600/pagination+without+refresh.png this will solve the whole page refresh problem, but now I want to filter the table from an input box for example if I have 100 records, when I type in 50 in the input box, the grid will return the first 50 records only, how would I go about solving this problem that avoids the page refresh problem? --
[web2py] Re: SQLFORM.grid pagination refresh
the problem is whatever I do, the clicking the pagination triggers a whole page refresh, the links are not trapped, This describes the problem Trapped Ajax links A Ajax links Normally a link is not trapped, and by clicking in a link inside a component, the entire linked page is loaded. Sometimes you want the linked page to be loaded inside the component. This can be achieved using the A helper: 1. {{=A('linked page',_href='http://example.com',cid=request.cid)}} If cid is specified, the linked page is loaded via Ajax. The cid is the id of the html element where to place the loaded page content. In this case we set it to request.cid, i.e. the id of the component that generates the link. The linked page can be and usually is an internal URL generated using the URL command. --
[web2py] Re: SQLFORM.grid pagination refresh
I see. I was responding to your request for filtering (e.g., showing only 50 records). If you put the grid in a web2py component (e.g., via LOAD()), then the links should automatically get trapped. Is there a reason you don't want to use a component? Anthony On Monday, July 23, 2012 5:09:52 PM UTC-4, dave wrote: the problem is whatever I do, clicking the pagination triggers a whole page refresh, the links are not trapped, This describes the problem Trapped Ajax links A Ajax links Normally a link is not trapped, and by clicking in a link inside a component, the entire linked page is loaded. Sometimes you want the linked page to be loaded inside the component. This can be achieved using the A helper: 1. {{=A('linked page',_href='http://example.com',cid=request.cid)}} If cid is specified, the linked page is loaded via Ajax. The cid is the id of the html element where to place the loaded page content. In this case we set it to request.cid, i.e. the id of the component that generates the link. The linked page can be and usually is an internal URL generated using the URL command. --
[web2py] Re: SQLFORM.grid pagination refresh
No. On Sunday, 22 July 2012 21:38:15 UTC-5, dave wrote: Is there a way for SQLFRORM.grid pagination to not refresh the whole page without the use of the LOAD function? --
[web2py] Re: SQLFORM.grid pagination refresh
Wow, that was fast, first time asker here, I have an SQLFORM.grid in a view, when I click the pagination links at the bottom of the page 1, 2, 3 etc, the whole page refreshes. To avoid this problem, I created a component and put it in a view div id=grid {{=LOAD('default','ajaxTable2.load',ajax=True, target='grid', content='loading...')}} /div https://lh5.googleusercontent.com/-IuP9zYl2i3E/UAzI4jmSzaI/CrA/tjLj4mSDifA/s1600/pagination+without+refresh.png this will solve the whole page refresh problem, but now I want to filter the table from an input box for example if I have 100 records, when I type in 50 in the input box, the grid will return the first 50 records only, how would I go about solving this problem that avoids the page refresh problem? --