Hi,
I am newbie and I have written with the Example codes. But it does not
quite.
I can 'edit' but not 'add' and 'delete'.
What ist wrong or what is missing ?
Thanks and sorry for my englisch.
The following is part of the code:
------------------
Controller:
------------------
@service.json
def getjson():
page=int((request.vars.page))
limit=int((request.vars.rows))
rcount=db(db.things.id>0).count()
total_pages=int(ceil(rcount*1.0/limit))
start = limit*page-limit
records = db(db.things.id>0).select(limitby=(start,start+limit))
cellist=[]
mylist={}
mylist['total']=str(total_pages)
mylist['page']=str(page)
mylist['records']=str(rcount)
for row in records:
temp={}
temp['id']=str(row.id)
temp['cell']=[row.id,row.name,row.category,row.price,row.owner]
cellist=cellist+[temp]
mylist['rows']=cellist
return(mylist)
@service.json
def setjson():
value=request.vars
id=value['id']
name=value['name']
category=value['category']
price=value['price']
owner=value['owner']
db(db.things.id==id).update(name=name, category=category,
price=price, owner=owner)
------------------------
View.html
------------------------
{{extend 'layout.html'}}
<script>
jQuery("#list").jqGrid('navGrid',selector,options,pEdit,pAdd,pDel,pSearch );
</script>
<script>
jQuery(document).ready(function(){
jQuery("#list").jqGrid({
url:'{{=URL(r=request,f='call',args=['json','getjson'])}}',
data: "{}",
datatype: 'json',
mtype: 'GET',
contentType: "application/json; charset=utf-8",
complete: function(jsondata, stat) {
if (stat == "success") {
var thegrid = jQuery("#list")[0];
thegrid.addJSONData(JSON.parse(jsondata.responseText).d);
}
},
colNames:['ID','Name','Category', 'Price','Owner'],
colModel :[
{name:'id',index:'id', width:55,sortable:false, editable:true,
editoptions:{readonly:true,size:10}},
{name:'name', index:'name',width:200,editable:true},
{name:'category', index:'category',width:200,editable:true},
{name:'price', index:'price',width:200,editable:true},
{name:'owner', index:'owner',width:200,editable:true},
],
jsonReader : {
repeatitems:true
},
pager: '#pager',
rowNum:10,
rowList:[10,20,30],
sortname: 'name',
sortorder: 'desc',
viewrecords: true,
caption: 'Test Grid',
editurl:'{{=URL(r=request,f='call',args=['json','setjson'])}}'}).navGrid('#pager');
});
jQuery("#list").jqGrid('navGrid','#pager',
{view:true}, //options
{height:290,reloadAfterSubmit:false, jqModal:false,
closeOnEscape:true, bottominfo:"Fields marked with (*) are
required"}, // edit options
{height:290,reloadAfterSubmit:false,jqModal:false,
closeOnEscape:true,bottominfo:"Fields marked with (*) are required",
closeAfterAdd: true}, // add options
{reloadAfterSubmit:false,jqModal:false, closeOnEscape:true}, // del
options
{closeOnEscape:true}, // search options
{height:250,jqModal:false,closeOnEscape:true} // view options
);
<table id="list"></table>
<div id="pager"></div>