<script src="{{=URL('static','js/jquery.jeditable.js')}}"></script>
db.define_table('dogs',
Field('dog_name','string'))
def populate():
db.dogs.insert(dog_name='dagwood')
db.dogs.insert(dog_name='daisy')
def dogs():
db.dogs.dog_name.represent = lambda value, row: DIV(value if value else '-',_class='dog_name', _id=str(row.id)+'.dog_name')
g = SQLFORM.grid(db.dogs, searchable=False, csv=False, user_signature=False)
return dict(form = g)
def upd_dog_name():
id,column = request.post_vars.id.split('.')
value = request.post_vars.value
db(db.dogs.id == id).update(**{column:value})
return value
{{extend 'layout.html'}}
<script>
jQuery(document).ready(function(){
jQuery('.dog_name').editable("{{=URL('dogs', 'upd_dog_name')}}",{
tooltip: "Click to edit, enter to save",
indicator : 'updating',
});})
</script>
<div id='dogs'>
{{=form}}
</div>
Download jeditable,Install in the static/js folder.Include in layout.html i.e.
<script src="{{=URL('static','js/jquery.jeditable.js')}}"></script>Model
db.define_table('dogs',
Field('dog_name','string'))Controller:
def populate():
db.dogs.truncate()
db.fleas.truncate()
db.dogs.insert(dog_name='dagwood')
db.dogs.insert(dog_name='daisy')
def dogs():
db.dogs.dog_name.represent = lambda value, row: DIV(value if value else '-',_class='dog_name', _id=str(row.id)+'.dog_name')
g = SQLFORM.grid(db.dogs, searchable=False, csv=False, user_signature=False)
return dict(form = g)
def upd_dog_name():
id,column = request.post_vars.id.split('.')
value = request.post_vars.value
db(db.dogs.id == id).update(**{column:value})
return value
Traceback (most recent call last):
File "/Users/myname/PycharmProjects/DataBaseExamples/web2py/gluon/restricted.py", line 217, in restricted
exec ccode in environment
File "/Users/myname/PycharmProjects/DataBaseExamples/web2py/applications/DataBaseExamples/controllers/jeditable.py", line 19, in <module>
File "/Users/myname/PycharmProjects/DataBaseExamples/web2py/gluon/globals.py", line 371, in <lambda>
self._caller = lambda f: f()
line 14, in upd_dog_name
id,column = request.post_vars.id.split('.') #'NoneType' object has no attribute 'split'
AttributeError: 'NoneType' object has no attribute 'split'
-----------------------------------
Did you take the code from a working example?
Thanks for your help!
pd
Hi Simon,
I just found the problem:
The line:
<script src="{{=URL('static','js/jquery.jeditable.js')}}"></script>
has to be inserted after(!)
{{include 'web2py_ajax.html'}}
which adds jquery.js
Changing that, first my inline changes were reverted, but when I adapted the location
in the line
jQuery('.dog_name').editable("{{=URL('jeditable', 'upd_dog_name')}}",{
to my location of „upd_dog_name“ now it works perfect!
Thank you very much for this wonderful example: I learned a lot with it, especially how to pass data from web2py/python to javascript and back.
And this inline-editing is very useful too :-)
This should be integrated into web2py and/or the quick examples!
Do you have more examples of this kind? :-)
Excellent! Perfect! 10 of 10 stars! Thanks a lot!
pd
--
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.
For more options, visit https://groups.google.com/groups/opt_out.