Hi All, I still get a ticket if I use fields code as mentioned by Johann (I am using latest stable - web2py 1.99.2 not trunk) , does it work with the trunk version?
Result1: fields = (db.projects_post.title, db.projects_posts.project_details, db.projects_posts.estimated_worth ) TRACEBACK ----------------------- Traceback (most recent call last): File "D:\WEB2PY\web2py\gluon\restricted.py", line 194, in restricted exec ccode in environment File "D:/WEB2PY/web2py/applications/Link_IT/controllers/default.py", line 159, in <module> File "D:\WEB2PY\web2py\gluon\globals.py", line 149, in <lambda> self._caller = lambda f: f() File "D:/WEB2PY/web2py/applications/Link_IT/controllers/default.py", line 37, in index deletable=False, editable=True, csv=False, maxtextlength=64, paginate=20 ) File "D:\WEB2PY\web2py\gluon\sqlhtml.py", line 1652, in grid id = row[field_id] File "D:\WEB2PY\web2py\gluon\dal.py", line 3842, in __getitem__ return dict.__getitem__(self, key) KeyError: 'id' #-------------- Result2: Changing base.css fixed the View rendered by the grid for huge texts (my Q3 above) - below code/prameter change worked - .web2py_grid td { white-space:wrap; } /*changed from nowrap to wrap */ Result3: The below code for specifying a custom link works with web2py(1.99.2) provided you have a valid function called view in your controller links = [lambda row: A('View Post',_href=URL("default","view",args=[row.id]))] Result4: Code like below works! db.projects_posts.id.readable=False # does not show the id in views May be I'll try with latest web2py in trunk for the fields issue. Thanks and Regards, Rahul (www.flockbird.com - web2py powered) --------------------------------------------- On Nov 16, 2:29 am, Cliff <cjk...@gmail.com> wrote: > About Q2: > links = [lambda row: > A('View',_href=URL("default","view",args=[row.id]))] > > if auth.has_membership('editors'): > links.append([lambda row: > A('Edit',_href=URL("default","edit",args=[row.id]))] ) > if auth.has_membership('deleters'): > lambda row: > A('Delete',_href=URL("default","delete",args=[row.id]))] > > About Q4: > In your controller, do something like: > > if len(request.args)>2 and request.args[-3] in ['edit', 'view']: > db.table.view.readable=False > db.table.view.writable=False > > Do this before the call to grid. > > On Nov 15, 9:17 am, Jim Steil <j...@qlf.com> wrote: > > > > > > > > > As Johann mentioned, the format of your fields var is wrong. Change to > > db.tablename.fieldname instead of 'tablename.fieldname' and you should > > be good. > > > Regarding Cliff's comment, all my experience (and therefore advice) is > > coming from running trunk, not 1.99.2. > > > Q1 - By links above, I meant - the add, delete, edit and view buttons > > that are on the SQLForm.grid - Is there a way to add custom code for > > it? With my new application, it works out of the box though and it > > requires me to login. > > > You can supply a 'links' arg on your call to .grid. I believe it is a list > > of buttons that can be defined and added to the grid. I haven't used it, > > but found this example on the web: > > > links = [lambda row: A('Edit',_href=URL("default","edit",args=[row.id])), > > lambda row: > > A('Delete',_href=URL("default","delete",args=[row.id]))] > > > Q2 - Can I use those button functions without authorization? > > > I believe you need authorization with the default links. Don't know if you > > use custom links as described above. > > > Q3 - Is there a way to format the View rendered by the grid? Since the > > "text" datatype field of Database containing huge text goes out of the > > layout. It expands it horizontally. > > > I would think you'd be able to fix this with CSS. Are you familiar with > > firebug? This would help you find the exact settings that would affect > > that field. > > > Q4 - How can I hide ID field from showing up while viewing or > > modifying data ? > > > Set the id field to readable=False, writable=False in your controller > > function before displaying the grid. > > > Hope this helps. Let me know if you have more questions. The new .grid > > and .smartgrid are amazing features of web2py. > > > -Jim > > > On 11/15/2011 5:39 AM, Rahul wrote: > > > > Hi All, > > > Thanks for your help and wonderful posts - I cleared the css > > > mess and I was able to see the SQLForm.grid properly. I tried working > > > with multiple and even updated plugin layouts but it does not display > > > the SQLForm.grid properly if I have a plugin_layouts thing. With > > > default scaffolding application, it works like a charm- Here are my > > > findings - Created a new application. > > > > Jim - If I use fields=fields , I get below traceback (Note > > > columns=fields works fine) - have a look at code listing below - > > > [Note: this is in index() function ] > > > > --- > > > query = ((db.projects_posts.post_visibility=="Classified")) > > > fields = ('projects_posts.title', > > > 'projects_posts.project_details', > > > 'projects_posts.estimated_worth' > > > ) > > > headers ={'projects_posts.title': 'Title', > > > 'projects_posts.project_details': 'Details', > > > 'projects_posts.estimated_worth': 'Worth'} > > > > ##columns=fields works, but fields=fields throws a ticket ..see > > > below > > > form = SQLFORM.grid( query=query, columns=fields, headers=headers, > > > deletable=False, editable=False, csv=False, > > > maxtextlength=64, paginate=10 ) > > > > return dict(form=form) > > > ------------------------------------- > > > TRACEBACK > > > ------------------------------------- > > > > Traceback (most recent call last): > > > File "D:\WEB2PY\web2py\gluon\restricted.py", line 194, in restricted > > > exec ccode in environment > > > File "D:/WEB2PY/web2py/applications/Link_IT/controllers/default.py", > > > line 162, in<module> > > > File "D:\WEB2PY\web2py\gluon\globals.py", line 149, in<lambda> > > > self._caller = lambda f: f() > > > File "D:/WEB2PY/web2py/applications/Link_IT/controllers/default.py", > > > line 40, in index > > > deletable=False, editable=False, csv=False, maxtextlength=64, > > > paginate=10 ) > > > File "D:\WEB2PY\web2py\gluon\sqlhtml.py", line 1588, in grid > > > if not field.readable: continue > > > AttributeError: 'str' object has no attribute 'readable' > > > > Now some questions - > > > Q1 - By links above, I meant - the add, delete, edit and view buttons > > > that are on the SQLForm.grid - Is there a way to add custom code for > > > it? With my new application, it works out of the box though and it > > > requires me to login. > > > Q2 - Can I use those button functions without authorization? > > > Q3 - Is there a way to format the View rendered by the grid? Since the > > > "text" datatype field of Database containing huge text goes out of the > > > layout. It expands it horizontally. > > > Q4 - How can I hide ID field from showing up while viewing or > > > modifying data ? > > > > Please excuse me for asking so many questions but this is the best > > > place to get the answers. Please let me know on above questions. I > > > also intend to put up a web2pyslice for SQLForm.grid once I am done > > > with it completely. Thanks > > > > More questions to follow... > > > > Thanks and Sincerely, Rahul > > > (www.flockbird.com-web2py powered) > > > > --------------------------------------------------------------------------- > > > --------- > > > On Nov 15, 5:28 am, Massimo Di Pierro<massimo.dipie...@gmail.com> > > > wrote: > > >> true. fields should also work with expressions > > >> db.table.field1*db.table.field2+1 although I did not try. > > > >> On Nov 14, 3:36 pm, JaapP<j...@tetra.nl> wrote: > > > >>> One more reason to stick to using fields could be that with fields you > > >>> can specify the order in which the columns are shown, this didn't work > > >>> for 'columns' > > >>> On 14 nov, 18:13, Jim Steil<j...@qlf.com> wrote: > > >>>> Ok, columns are gone again... > > >>>> Might just be best to stick with using fields. > > >>>> -Jim > > >>>> On 11/14/2011 8:47 AM, Jim Steil wrote: > > >>>>> I stand corrected on the 'columns' comment. Massimo added it back in > > >>>>> this morning. > > >>>>> -Jim > > >>>>> On 11/14/2011 8:45 AM, Jim Steil wrote: > > >>>>>> here are a few thoughts... > > >>>>>> 1. Make sure you create this test in a new app. If you're updating > > >>>>>> or adding functionality to an already existing app, then your layout > > >>>>>> and base.css need to be updated. > > >>>>>> 2. If using jquery-ui, then you need to download jquery-ui and > > >>>>>> include it in your layout.html with a line like this: > > >>>>>> {{response.files.append(URL('static','jquery-ui/js/jquery-ui-1.8.16.custom. > > >>>>>> min.js'))}} > > >>>>>> {{response.files.append(URL('static','jquery-ui/css/sunny/jquery-ui-1.8.16. > > >>>>>> custom.css'))}} > > >>>>>> 3. Don't use the 'columns' argument. It is going away in the next > > >>>>>> release. Instead, use 'fields'. In your case, use the following: > > >>>>>> fields = [db.projects_posts.title, db.projects_posts.project_details, > > >>>>>> db.projects_posts.estimated_worth] > > >>>>>> 4. I typically do not specify the 'headers' arg. Instead, set the > > >>>>>> 'label' on your table definition. That way you only have to do it > > >>>>>> once and can use it all over. If you need to override it for a > > >>>>>> particular function, then just set the 'label' attribute in that > > >>>>>> function. > > >>>>>> 5. At this time there is no documentation available for SQLFORM.grid > > >>>>>> or SQLFORM.smartgrid. The best thing to do would be to look through > > >>>>>> this group for all the posts. Massimo is working on an updated > > >>>>>> version of that manual that he is hoping to have complete by the end > > >>>>>> of this month. That should contain information on .grid and > > >>>>>> .smartgrid. > > >>>>>> 6. If you are going to be playing around with this I would recommend > > >>>>>> that you work with the code in trunk. I don't recall what state the > > >>>>>> .grid was in when 1.99.2 was released. > > >>>>>> As for answers for your specific questions: > > >>>>>> Q: What is the exact proper method to use SQLForm.grid - > > >>>>>> I think your on the right track. Just need to clean up your css and > > >>>>>> layout.html files to get the proper formatting. > > >>>>>> Q: What all libraries do I need to include? where? > > >>>>>> If you want to use jquery-ui then you need to download it and > > >>>>>> reference it in your layout.html. > > >>>>>> Q: How to make links work the way they should ? > > >>>>>> I'd like some more information on what is going on here before giving > > >>>>>> an answer. > > >>>>>> Q: Can search be customized? How? > > >>>>>> I don't remember if the search_form is implemented in 1.99.2, but > > >>>>>> there is a search facility built in that allows the users to create a > > >>>>>> custom search. I am not a fan of it and have some other ideas how > > >>>>>> developers could be allowed to create custom search forms, but I > > >>>>>> haven't opened a ticket on it yet. > > >>>>>> Q: Is this documented in online book? - did not find much about it > > >>>>>> in > > >>>>>> version 3.2 though. > > >>>>>> Documentation will be coming with the next version of the book > > >>>>>> targeted for the end of the month. > > >>>>>> Hope this helps. > > >>>>>> -Jim > > >>>>>> On 11/14/2011 6:54 AM, Rahul wrote: > > >>>>>>> Hi All, > > >>>>>>> Can anyone let me know how to use SQLForm.grid properly or > > >>>>>>> tell > > >>>>>>> me what I am missing. I have not installed any jquery plugin for the > > >>>>>>> same (assuming that it... > > read more »