Michele,

Thanks so much for this.

I tried to remove the select action and change the view as suggested but 
that wasn't working. So, I experimented with the redirect from the select 
action
to the index a couple of times.

I removed the request.vars.id, from the redirect and now it's working! The 
redirect looks like this now:

redirect(URL('index', args=[request.vars.page]))

So it's working! Thanks again very much! I really appreciate it.

On Monday, January 5, 2015 6:37:54 AM UTC+8, Michele Comitini wrote:
>
> Joe,
>
> If you stay on page 1, it's because you do not pass the args parameter 
> correctly, when doing the redirect.
> check you pass the variable page to the select() function and also that 
> when you redirect back to index you pass correctly the page as 
> request.args(0)
>
> also simplify your code by removing the select action and by putting in 
> the beginning of the index action:
>
>   id = request.vars.id
>   if id:
>     name = db(db.post. <http://db.post.id>
> id==id).update(selected=(db.post.selected==False))
>
> and in the view:
>   
> {{=A('Select', _id = i.id, _class="btn btn-danger",_href=URL("index#%s" % 
> i.id, args=[page] <http://i.id/>, vars=dict(id=i.id,page=page)))}}
>
> {{elif i.selected:}}
> {{=A('Selected', _id = i.id, _class="btn btn-info",_href=URL("index#%s" % 
> i.id, args=[page] <http://i.id/>, vars=dict(id=i.id, page=page 
> <http://i.id/>)))}}
>
> 2015-01-03 22:43 GMT+01:00 Joe <degrou...@gmail.com <javascript:>>:
>
>> Hi Michele, thanks so much for looking at this problem. I appreciate it 
>> very much. I tried the code but after selecting, the user is still sent 
>> back to page 1 each time, not staying on the same page.
>>
>>
>> On Friday, January 2, 2015 10:18:44 PM UTC+8, Michele Comitini wrote:
>>>
>>> in the view links add the page and element id:
>>>
>>> {{=A('Select', _id = i.id, _class="btn btn-danger",_href=URL("select", 
>>> args=i.id, vars=dict(id=i.id,page=page)))}}
>>>
>>> {{elif i.selected:}}
>>> {{=A('Selected', _id = i.id, _class="btn btn-info",_href=URL("select", 
>>> args=i.id, vars=dict(id=i.id, page=page <http://i.id/>)))}}
>>>
>>>
>>> in action select() do:
>>> redirect(URL('index#' + request.vars.id, args=[request.vars.page]))
>>>
>>> no return needed!
>>>
>>> Actually you could resort to using AJAX for instance by using
>>> {{=A('Selected', _id = i.id, _onclick="jQuery.get(" +URL('select', 
>>> args=[i.id]).... ...
>>> and use jQuery itself to manipulate the css class of the button itself
>>>
>>>
>>>
>>>
>>> Il giorno giovedì 20 novembre 2014 04:59:11 UTC+1, Joe ha scritto:
>>>>
>>>> @Massimo, Thanks very much Massimo. I am trying to find a way to 
>>>> redirect the user to the page where the user clicks on the select button 
>>>> to 
>>>> select an item. The user might be on page 2 or page 3 page 4 or any other 
>>>> page when he selects the item. How can I redirect the user to the same 
>>>> page 
>>>> he is on when making the selection.
>>>>
>>>> This is the View for the Controller code I posted:
>>>>
>>>> {{extend 'layout.html'}}
>>>> {{for i in rows:}}
>>>> <div class="well">
>>>> <h5>{{=i.name}}</h5>
>>>> {{if not i.selected:}}
>>>> {{=A('Select',_class="btn btn-danger",_href=URL("select",args=i.id, 
>>>> vars=dict(id=i.id)))}}
>>>> {{elif i.selected:}}
>>>> {{=A('Selected',_class="btn btn-info",_href=URL("select",args=i.id, 
>>>> vars=dict(id=i.id)))}}
>>>> {{pass}}
>>>> </div>
>>>> {{pass}}
>>>> <br><br>
>>>> {{if page:}}
>>>> <a href="{{=URL(r=request, args=[page-1])}}">previous</a>
>>>> {{pass}}
>>>> {{if len(rows)>=items_per_page:}}
>>>> <a href="{{=URL(r=request, args=[page+1])}}">next</a>
>>>> {{pass}}
>>>>
>>>> On Thursday, November 20, 2014 11:38:05 AM UTC+8, Massimo Di Pierro 
>>>> wrote:
>>>>>
>>>>> URL('index',args=(2)) will give you page #2.
>>>>>
>>>>>
>>>>> On Monday, 17 November 2014 22:59:16 UTC-6, Joe wrote:
>>>>>>
>>>>>> Thanks Cliff, I've been trying to do that but I didn't succeed. I 
>>>>>> would appreciate if you could send an example on how to put the current 
>>>>>> page info in the request.args dictionary.
>>>>>>
>>>>>> On Tuesday, November 18, 2014 12:37:09 PM UTC+8, Cliff Kachinske 
>>>>>> wrote:
>>>>>>>
>>>>>>> Put information about the current page in the request.args 
>>>>>>> dictionary. You could use the session, but if your user opens a second 
>>>>>>> browser window it becomes difficult to keep track of which session data 
>>>>>>> corresponds to which browser tab.
>>>>>>>
>>>>>>>
>>>>>>>  -- 
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to web2py+un...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to