- 浏览: 61435 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
u014549257:
...
Apache Mina: StreamIoHandler传输文件处理 -
至尊包:
想问一下,这个官网的列子如果要兼容3.0以下的版本要怎么处理? ...
Swipe Views (水平分页)
数据类型
xml, json, jsonp, array, xmlstring, jsonstring, script, function (…)
xml类型默认解析如下:
json数据默认解析如下:
XML数据
XML数据解析时有几个重要的元素:root, row, page, total, records, repeattimes, cell,id
举个例子:
使用js解析时:
如果XML结构如下:
js源码:
xml string
数据类型:json, jsonp, (jsonstring)
主要数据元素:root, page, total,records, row, cell, id, repeatitems,
默认的JS结构:
json的数据结构:
repeatitems的使用:
json:
json string
colModel:
json string:
jsonReader as function
此处的 obj 是从服务端服务器的response。
Array Data
相关的配置:datatype
colModel的相关选项: sorttype, datefmt
相关的方法:getRowData, delRowData, setRowData, addRowData, updateGridRows
js
语法:
1. jQuery("#grid_id").addRowData( rowid, data, position, srcrowid );
position: 增加数据的位置:first, last, before or after. 1) first:增加在最前面,2)last:增加在最后面,3) before”,“after” srcrowid参数的前面或后面。
srcrowid: 和position中的“before”,“after”配合使用。
2. jQuery("#grid_id").getRowData( rowid );
3. jQuery("#grid_id").delRowData( rowid );
4. jQuery("#grid_id").setRowData( rowid, data );
Function
User Data
xml
json
获取userdata的方法:
jQuery("grid_id").jqGrid('getGridParam', 'userData')
xml, json, jsonp, array, xmlstring, jsonstring, script, function (…)
xml类型默认解析如下:
jQuery("#gridid").jqGrid({ ... xmlReader : { root: "rows", row: "row", page: "rows>page", total: "rows>total", records : "rows>records", repeatitems: true, cell: "cell", id: "[id]", userdata: "userdata", subgrid: { root:"rows", row: "row", repeatitems: true, cell:"cell" } }, ... });
json数据默认解析如下:
jQuery("#gridid").jqGrid({ ... jsonReader : { root: "rows", page: "page", total: "total", records: "records", repeatitems: true, cell: "cell", id: "id", userdata: "userdata", subgrid: { root:"rows", repeatitems: true, cell:"cell" } }, ... });
XML数据
XML数据解析时有几个重要的元素:root, row, page, total, records, repeattimes, cell,id
举个例子:
...... <invoices> <request>true</request> ... <currentpage>1</currentpage> // page <totalpages>10</totalpages> //total <totalrecords>20</totalrecords> //records <result> // root <invoice asin='12345'> // id // 都是用 <invcell></invcell>, repeateitems: true <invcell>data1</invcell> // cell <invcell>data2</invcell> <invcell>data3</invcell> <invcell>data4</invcell> <invcell>data5</invcell> <invcell>data6</invcell> </invoice> ... </result> </invoices>
使用js解析时:
jQuery("#gridid").jqGrid({ ... xmlReader: { root:"result", row:"invoice", page:"invoices>currentpage", total:"invoices>totalpages", records:"invoices>totalrecords", repeatitems:true, cell:"invcell", id : "[asin]" }, ... });
如果XML结构如下:
... <invoices> <request>true</request> ... <currentpage>1</currentpage> <totalpages>10</totalpages> <totalrecords>20</totalrecords> <result> <invoice> // 以下TAG不同,这repeatitems: false <asin>12345</asin> <invoiceno>data1</invoiceno> <invoicedate>data2</invoicedate> <invoiceamount>data3</invoiceamount> <invoicetax>data4</invoicetax> <invoicetotal>data5</invoicetotal> <notes>data6</notes> </invoice> ... </result> </invoices>
js源码:
jQuery("#gridid").jqGrid({ ... xmlReader: { root:"result", row:"invoice", page:"invoices>currentpage", total:"invoices>totalpages", records:"invoices>totalrecords", repeatitems:false, id : "asin" }, ... }); and our colModel from the example should look like this: <code javascript> jQuery("#gridid").jqGrid({ ... // 作个XML TAG和 colModel的映射关系 // 如果不作映射关系,name的值必须是xml里的tag名称。 colModel :[ {name:'invid', index:'invid', width:55, xmlmap:"invoiceno"}, {name:'invdate', index:'invdate', width:90, xmlmap:"invoicedate"}, {name:'amount', index:'amount', width:80, align:'right', xmlmap:"invoiceamount"}, {name:'tax', index:'tax', width:80, align:'right', xmlmap:"invoicetax"}, {name:'total', index:'total', width:80, align:'right', xmlmap:"invoicetotal"}, {name:'note', index:'note', width:150, sortable:false, xmlmap:"notes"} ], xmlReader: { root:"result", row:"invoice", page:"invoices>currentpage", total:"invoices>totalpages", records:"invoices>totalrecords", repeatitems:false, id : "asin" }, ... });
xml string
<script> var mystr = "<?xml version='1.0' encoding='utf-8'?> <invoices> <rows> <row> <cell>data1</cell> <cell>data2</cell> <cell>data3</cell> <cell>data4</cell> <cell>data5</cell> <cell>data6</cell> </row> </rows> </invoices>"; jQuery(document).ready(function(){ jQuery("#list").jqGrid({ datatype: 'xmlstring', datastr : mystr, colNames:['Inv No','Date', 'Amount','Tax','Total','Notes'], colModel :[ {name:'invid', index:'invid', width:55, sorttype:'int'}, {name:'invdate', index:'invdate', width:90, sorttype:'date', datefmt:'Y-m-d'}, {name:'amount', index:'amount', width:80, align:'right', sorttype:'float'}, {name:'tax', index:'tax', width:80, align:'right', sorttype:'float'}, {name:'total', index:'total', width:80, align:'right', sorttype:'float'}, {name:'note', index:'note', width:150, sortable:false} ], pager: '#pager', rowNum:10, viewrecords: true, caption: 'My first grid' }); }); </script>
数据类型:json, jsonp, (jsonstring)
主要数据元素:root, page, total,records, row, cell, id, repeatitems,
默认的JS结构:
jQuery("#gridid").jqGrid({ ... jsonReader : { root: "rows", page: "page", total: "total", records: "records", repeatitems: true, cell: "cell", id: "id", userdata: "userdata", subgrid: {root:"rows", repeatitems: true, cell:"cell" } }, ... });
json的数据结构:
{ "total": "xxx", "page": "yyy", "records": "zzz", "rows" : [ {"id" :"1", "cell" :["cell11", "cell12", "cell13"]}, {"id" :"2", "cell":["cell21", "cell22", "cell23"]}, ... ] }
repeatitems的使用:
jQuery("#gridid").jqGrid({ ... jsonReader : { root:"invdata", page: "currpage", total: "totalpages", records: "totalrecords", repeatitems: false, id: "0" }, ... });
json:
{ "totalpages" : "xxx", "currpage" : "yyy", "totalrecords" : "zzz", "invdata" : [ {"invid" : "1","invdate":"cell11", "amount" :"cell12", "tax" :"cell13", "total" :"1234", "note" :"somenote"}, {"invid" : "2","invdate":"cell21", "amount" :"cell22", "tax" :"cell23", "total" :"2345", "note" :"some note"}, ... ] }
json string
colModel:
jQuery("#gridid").jqGrid({ ... colModel:[ {name:'name',label:'Name', width:150,editable: true}, {name:'id',width:50, sorttype:"int", editable: true,formatter:strongFmatter}, {name:'email',label:'Email', width:150,editable: true,formatter:'email'}, {name:'stock',label:'Stock', width:60, align:"center", editable: true,formatter:'checkbox',edittype:"checkbox"}, {name:'item.price',label:'Price', width:100, align:"right", editable: true,formatter:'currency'}, {name:'item.weight',label:'Weight',width:60, align:"right", editable: true,formatter:'number'}, {name:'ship',label:'Ship Via',width:90, editable: true,formatter:'select', edittype:"select",editoptions: value:"2:FedEx;1:InTime;3:TNT;4:ARK;5:ARAMEX"}}, {name:'note',label:'Notes', width:100, sortable:false,editable: true,edittype:"textarea", editoptions:{rows:"2",cols:"20"}} ], ... });
json string:
{ "page":"1", "total":2, "records":"13", "rows":[ {"id":"12345","name":"Desktop Computers","email":"josh@josh.com","item":{"price":"1000.72", "weight": "1.22" }, "note": "note", "stock": "0","ship": "1"}, {"id":"23456","name":"<var>laptop</var>","note":"Long text ","stock":"yes","item":{"price":"56.72", "weight":"1.22"},"ship": "2"}, {"id":"34567","name":"LCD Monitor","note":"note3","stock":"true","item":{"price":"99999.72", "weight":"1.22"},"ship":"3"}, {"id":"45678","name":"Speakers","note":"note","stock":"false","ship":"4"} ] }
jsonReader as function
jsonReader: { repeatitems: false, id: "Id", root: function (obj) { return obj; }, page: function (obj) { return 1; }, total: function (obj) { return 1; }, records: function (obj) { return obj.length; } }
此处的 obj 是从服务端服务器的response。
Array Data
相关的配置:datatype
colModel的相关选项: sorttype, datefmt
相关的方法:getRowData, delRowData, setRowData, addRowData, updateGridRows
localReader = { root: "rows", page: "page", total: "total", records: "records", repeatitems: false, cell: "cell", id: "id", userdata: "userdata", subgrid: {root:"rows", repeatitems: true, cell:"cell"} }
js
... <script> jQuery(document).ready(function(){ jQuery("#list").jqGrid({ datatype: 'clientSide', colNames:['Inv No','Date', 'Amount','Tax','Total','Notes'], colModel :[ {name:'invid',index:'invid', width:55, sorttype:'int'}, {name:'invdate',index:'invdate', width:90, sorttype:'date', datefmt:'Y-m-d'}, {name:'amount',index:'amount', width:80, align:'right',sorttype:'float'}, {name:'tax',index:'tax', width:80, align:'right',sorttype:'float'}, {name:'total',index:'total', width:80,align:'right',sorttype:'float'}, {name:'note',index:'note', width:150, sortable:false} ], pager: '#pager', rowNum:10, viewrecords: true, caption: 'My first grid' }); ... }); </script>
语法:
1. jQuery("#grid_id").addRowData( rowid, data, position, srcrowid );
position: 增加数据的位置:first, last, before or after. 1) first:增加在最前面,2)last:增加在最后面,3) before”,“after” srcrowid参数的前面或后面。
srcrowid: 和position中的“before”,“after”配合使用。
<script> ... var myfirstrow = {invid:"1", invdate:"2007-10-01", note:"note", amount:"200.00", tax:"10.00", total:"210.00"}; jQuery("#list").addRowData("1", myfirstrow); ... </script>
2. jQuery("#grid_id").getRowData( rowid );
jQuery("#list").getRowData( "1" ); 返回的数据: {invid:"1", invdate:"2007-10-01", note:"note", amount:"200.00", tax:"10.00", total:"210.00"};
3. jQuery("#grid_id").delRowData( rowid );
jQuery("#list").delRowData( "2" );
4. jQuery("#grid_id").setRowData( rowid, data );
jQuery("#list").setRowData( "1", { tax:"5", total:"205" });
Function
<script type="text/javascript"> ... jQuery(document).ready(function(){ jQuery("#list").jqGrid({ datatype: function(postdata) { jQuery.ajax({ url: 'example.php', data:postdata, dataType:"xml", complete: function(xmldata,stat){ if(stat=="success") { var thegrid = jQuery("#list")[0]; thegrid.addXmlData(xmldata.responseXML); } } }); }, colNames:['Inv No','Date', 'Amount','Tax','Total','Notes'], colModel :[ {name:'invid', index:'invid', width:55}, {name:'invdate', index:'invdate', width:90}, {name:'amount', index:'amount', width:80, align:'right'}, {name:'tax', index:'tax', width:80, align:'right'}, {name:'total', index:'total', width:80, align:'right'}, {name:'note', index:'note', width:150, sortable:false} ], pager: '#pager', rowNum:10, rowList:[10,20,30], sortname: 'invid', sortorder: 'desc', viewrecords: true, caption: 'My first grid' }); }); ... </script>
User Data
jsonReader: { ... userdata: "userdata", ... }
xml
<invoices> <request>true</request> <userdata name="totalinvoice"> 240.00 </userdata> // userdata <userdata name="tax"> 40.00</userdata> // userdata ... <result> <row> <cell>data1</cell> <cell>data2</cell> <cell>data3</cell> <cell>data4</cell> <cell>data5</cell> <cell>data6</cell> </row> ... </result> </invoices>
json
{ total: "xxx", page: "yyy", records: "zzz", userdata: {totalinvoice:240.00, tax:40.00}, // userdata rows : [ {id:"1", cell:["cell11", "cell12", "cell13"]}, {id:"2", cell:["cell21", "cell22", "cell23"]}, ... ] }
获取userdata的方法:
jQuery("grid_id").jqGrid('getGridParam', 'userData')
发表评论
-
jqGrid的使用笔记:5. 事件
2013-04-14 21:53 74221. 事件举例: var lastSe ... -
jqGrid的使用笔记:3. colModel API
2013-03-24 20:22 2240colmodel属性 colModel定义列属性, 语法是: ... -
jqGrid的使用笔记:2. 基本的Grid
2013-03-24 20:22 3362基本的方法 jQuery("#grid_id&quo ... -
jqGrid 的使用笔记:1. 开始
2013-03-22 21:26 1284来源 官方下载地址http://www.trirand.com ...
相关推荐
NULL 博文链接:https://jean7155.iteye.com/blog/1835073
jqgrid 使用: 数据加载 增加, 修改, 删除, 还原, 撤销等 逻辑上都做了很好的判断,希望能给你们带来帮助,以后也会持续更新jqgrid使用代码。
jqGrid使用笔记.docx
jqGrid没有setComplexGroupHeaders方法,使用此插件实现三级分组表头功能
jqGrid_api中文文档.doc
jquery.jqGrid-3.8.2.zipjquery.jqGrid-3.8.2.zipjquery.jqGrid-3.8.2.zipjquery.jqGrid-3.8.2.zipjquery.jqGrid-3.8.2.zipjquery.jqGrid-3.8.2.zip
jqgrid 中文文档离线demo打包. 下载 本地可架设运行
jquery.jqgrid
jQuery jqGrid 3.5 完整实例包.zip
jqGrid_JS_4.7.1.jq
jquery.jqGrid-4.5.2.zip 官方资源文件
软件介绍: jqGrid-5.1.0是很好用的jQuery表格插件,支持国际化具有bootstrap风格,通过使用jqGrid能实现前端页面与后台数据的ajax异步通信。
是用jqgrid必须的包,前台展示数据时,能更方便,漂亮的展示出来
tableExport 中文修正+jqgrid修正 表格导出插件,本插件在前人修正的基础上针对几个问题进行了修改,20170722修正以下问题:1.解决jqgrid无法获取表头问题;2.jqgrid开头有一空行问题;3.部分格式导出无扩展名问题;4....
jquery.jqGrid.js,jqGrid表格专用JS文件,缺失备用,即下即用。
很好的第三方控件,就是开始不太好上手,希望大神多出些完整的实力和文档。官方网址:http://www.trirand.com。
直接从官方网站上下载的。如果你还不了解Jqgrid网格插件的强大的处,也不了解Jqgrid的基本用法,可以先去www.javakfz.com看看关于Jqgrid的文章。
jqgrid
jqGrid使用帮助[参照].pdf