- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html lang="cn">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <!-- jqGrid 组件基础样式包 - 必要 -->
- <link rel="stylesheet" href="jqgrid/CSS/ui.jqgrid.css" />
- <!-- jqGrid 主题包 - 非必要 -->
- <!-- 在 jqgrid/css/css 这个目录下还有其他的主题包, 可以尝试更换看效果 -->
- <link rel="stylesheet" href="jqgrid/css/css/redmond/jquery-ui-1.8.16.custom.css" />
- <!-- jquery 插件包 - 必要 -->
- <!-- 这个是所有 jquery 插件的基础, 首先第一个引入 -->
- <script type="text/javascript" src="js/jquery-1.7.1.js"></script>
- <!-- jqGrid 插件包 - 必要 -->
- <script type="text/javascript" src="jqgrid/js/jquery.jqGrid.src.js"></script>
- <!-- jqGrid 插件的多语言包 - 非必要 -->
- <!-- 在 jqgrid/js/i18n 下还有其他的多语言包, 可以尝试更换看效果 -->
- <script type="text/javascript" src="jqgrid/js/i18n/grid.locale-cn.js"></script>
- <title>http://blog.mn886.net/jqGrid</title>
- <!-- 本页面初始化用到的 js 包, 创建 jqGrid 的代码就在里面 -->
- <script type="text/javascript" src="js/index.js"></script>
- </head>
- <body>
- <table id="list2"></table>
- <div id="pager2"></div>
- <br>
以上为创建 jqGrid 的简单例子想了解全功能 api, 请移步 < a href="http://blog.mn886.net/jqGrid">http://blog.mn886.net/jqGrid</a>
- </body>
- </html>
- $(function(){
- // 页面加载完成之后执行
- pageInit();
- });
- function pageInit(){
- // 创建 jqGrid 组件
- jQuery("#list2").jqGrid(
- {
- url : data/JSONData.json,// 组件创建完成之后请求数据的 url
- datatype : "json",// 请求数据返回的类型可选 json,xml,txt
- colNames : [ Inv No, Date, Client, Amount, Tax,Total, Notes ],//jqGrid 的列显示名字
- colModel : [ //jqGrid 每一列的配置信息包括名字, 索引, 宽度, 对齐方式.....
- {name : id,index : id,width : 55},
- {name : invdate,index : invdate,width : 90},
- {name : name,index : name asc, invdate,width : 100},
- {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}
- ],
- rowNum : 10,// 一页显示多少条
- rowList : [ 10, 20, 30 ],// 可供用户选择一页显示多少条
- pager : #pager2,// 表格页脚的占位符 (一般是 div) 的 id
- sortname : id,// 初始化的时候排序的字段
- sortorder : "desc",// 排序方式, 可选 desc,asc
- mtype : "post",// 向后台请求数据的 ajax 的类型可选 post,get
- viewrecords : true,
- caption : "JSON Example"// 表格的标题名字
- });
- /* 创建 jqGrid 的操作按钮容器 */
- /* 可以控制界面上增删改查的按钮是否显示 */
- jQuery("#list2").jqGrid(navGrid, #pager2, {edit : false,add : false,del : false});
- }
来源: http://www.bubuko.com/infodetail-2521483.html