sqlform.grid - Accessing id and values from link checkbox

700 views
Skip to first unread message

PremKumar KrishnaKumar

unread,
Jun 21, 2013, 3:00:43 AM6/21/13
to web...@googlegroups.com
Hi,
I am trying out webapp development using web2py and need your direction in finding a solution

I use links to display a check-box in sqlform.grid and in the form I have a button.

links = [dict(header='Actioned',body=lambda row: INPUT(_name='action',_type='checkbox'))]

Once I click the button I wanted to retrieve all the ids and flag and if it is checked update to 1 else 0.

Unfortunately i couldn't figure how to access the values also I don't want to call a controller function for every row but instead wanted to do it for all records displayed in the grid.

Would appreciate any direction that you could provide




Jim S

unread,
Jun 21, 2013, 10:37:21 AM6/21/13
to web...@googlegroups.com
Here is how I'm handling it:

    grid = SQLFORM.grid(query,fields=fields,create=False,editable=False,
                        details
=False,deletable=False,csv=False,
                        searchable
=False, orderby=orderby,
                        selectable
=lambda ids:redirect(URL('applications',
                                                       
'quickOrderConfirm',
                                                        vars
=dict(ids=ids))),
                        maxtextlength
=256,paginate=256)


Then in my applications/quickOrderConfirm function I use the following to grab the ids:

    feedOrderHistoryIds = []


   
if type(request.get_vars.ids) == type('str'):
        feedOrderHistoryIds
.append(request.get_vars.ids)
   
else:
       
for id in request.get_vars.ids:
            feedOrderHistoryIds
.append(id)


Isn't the prettiest code, but it is working for us.

-Jim

PremKumar KrishnaKumar

unread,
Jun 21, 2013, 11:50:23 AM6/21/13
to web...@googlegroups.com
Hi Jim,

The selectable works perfectly but the reason I am using links is I might require couple of more additional columns containing check-box.

So links could be used to add more colums

links = [dict(header='field1',body=lambda row: INPUT(_name='action',_type='checkbox')) ,
     dict(header='field2',body=lambda row: INPUT(_name='action',_type='checkbox'))
    ]

and i tried making calls through ajax _onclick=ajax() but they are made for every single selection but i wanted to process them together like selectable.

eg:
method1 = lambda ids: setindicator(ids)

grid = SQLFORM.grid(
            ...
            selectable=method1
            )
if i use selectable on clicking submit the method1 will be called with ids of the selected rows

similarly I am looking to create something which can pass all the ids and value of checkbox to the controller.
So If i have 5 elements in the grid the button once clicked should send the ids of 5 elements and their flag values. Selectable only sends the ids that are selected but through the links I am looking to get both selected and not selected ones.

probably like [(id1,1),(id2,0),(id3,1),(id4,0),(id5,1)] 1 - indicating selected, 0 - indicating not selected

Jim Steil

unread,
Jun 21, 2013, 4:14:28 PM6/21/13
to web...@googlegroups.com
Sorry, misunderstood what the problem was.


--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/RnGTZNERYic/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages