您的位置:首页 > 其它

jqgrid 一些要点

2015-09-21 11:14 190 查看
jqgrid cellsubmit属性:

1)设置为remote,单元格内容改变后将启动ajax请求cellurl配置的地址保存到服务器上。此数据行的id和修改的内容被附加到url上。配置了mtype为post提交,那么将会post提交键值对内容。例如,保存一个名为mycell的单元格
{id: rowid, mycell: cellvalue} 将会作为附加数据附加到url上。

2)设置为clientArray,不会发送ajax请求,修改后内容可以条用getChangedCells方法或者通过事件获取到 remote cellurl string 保存数据的url地址。cellsubmit设置为remote时一定要配置url地址。

jsonReader默认设置:

jsonReader : {
2     root: "rows",    // json中代表实际模型数据的入口
3     page: "page",    // json中代表当前页码的数据
4     total: "total",    // json中代表页码总数的数据
5     records: "records", // json中代表数据行总数的数据
6     repeatitems: true, // 如果设为false,则jqGrid在解析json时,会根据name来搜索对应的数据元素(即可以json中元素可以不按顺序);而所使用的name是来自于colModel中的name设定。
7     cell: "cell",
8     id: "id",
9     userdata: "userdata",
10     subgrid: {
11         root:"rows",
12         repeatitems: true,
13         cell:"cell"
14     }
15 }


通常jsonReader和repeatitems是配合使用的,如果repeatitems为false,json 中数据可以乱序,并且允许数据空缺。jqGrid会根据colModel中name属性和json数据对应,根据属性名称进行解析。

repeatitems为true时:
1     ...
2     jsonReader : {
3         root:"rows",
4         page: "page",
5         total: "total",
6         records: "records"
7     },
8     ...


json结构:
1 {
2     "page": "xxx",
3     "total": "yyy",
4     "records": "zzz",
5     "rows" : [
6                  {"id" :"1", "cell" :["cell11", "cell12", "cell13"]},    // cell中不需要各列的name,但是需要与colModel一一对应
7                  {"id" :"2", "cell" :["cell21", "cell22", "cell23"]},
8                  ...
9     ]
10 }


repeatitems为false时:
1     ...
2     repeatitems: false,
3     jsonReader : {
4         root:"rows",
5         page: "page",
6         total: "total",
7         records: "records"
8     },
9     ...


json结构:
1 {
2     "page" : "xxx",
3     "total" : "yyy",
4     "records" : "zzz",
5     "rows" : [
6          {"invid" : "1","invdate":"cell11", "amount" :"cell12", "tax" :"cell13", "total" :"1234", "note" :"somenote"}, // 数据中需要各列的name,但是可以不按列的顺序
7          {"invid" : "2","invdate":"cell21", "amount" :"cell22", "tax" :"cell23", "total" :"2345", "note" :"some note"},
8          ...
9     ]
10 }

注1:据其他网友的文章,如果设置repeatitems为false,不但数据可以乱序,而且不用每个数据元素都要具备,用到哪个找到哪个就可以了。

注2:cell、id在repeatitems为true时可以用到,即每一个记录是由一对id和cell组合而成,即可以适用另一种json结构。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: