JqGrid中文文档

最近使用JQGrid 发现其中文资料非常的少。几乎没有,而英文资料大部份是PHP。所以写一些资料方便自己和大家以后的使用。

先来看一个我在官方网站复制的简单的例子。

   1:  <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
   2:   
   3:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   4:  <html xmlns="http://www.w3.org/1999/xhtml">
   5:  <head id="Head1" runat="server">
   6:      <title>无标题页</title>
   7:      <link href="JS/jquery-ui-1.7.2.custom.css" rel="stylesheet" type="text/css" />
   8:      <link href="JS/ui.jqgrid.css" rel="stylesheet" type="text/css" />
   9:   
  10:      <script src="JS/jquery-1.3.2.min.js" type="text/javascript"></script>
  11:   
  12:      <script src="JS/grid.locale-cn.js" type="text/javascript"></script>
  13:   
  14:      <script src="JS/jquery.jqGrid.min.js" type="text/javascript"></script>
  15:      
  16:      <script type="text/javascript">
  17:      $(document).ready(function(){
  18:      
  19:          jQuery("#setcols").jqGrid({
  20:                 url:'Default2.aspx',
  21:              datatype: "json",
  22:                 colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
  23:                 colModel:[
  24:                     {name:'id',index:'id', width:55,hidedlg:true},
  25:                     {name:'invdate',index:'invdate', width:90,editable:true},
  26:                     {name:'name',index:'name asc, invdate', width:100},
  27:                     {name:'amount',index:'amount', width:80, align:"right",editable:true,editrules:{number:true}},
  28:   
  29:                     {name:'tax',index:'tax', width:80, align:"right",editable:true,editrules:{number:true}},        
  30:                     {name:'total',index:'total', width:80,align:"right"},        
  31:                     {name:'note',index:'note', width:150, sortable:false}        
  32:                 ],
  33:                 rowNum:10,
  34:                 pager: '#psetcols',
  35:                 sortname: 'id',
  36:              sortorder: "desc"
  37:          });
  38:      
  39:      })
  40:      
  41:   
  42:      </script>
  43:   
  44:  </head>
  45:  <body>
  46:      <table id="setcols">
  47:      </table>
  48:      <div id="psetcols">
  49:      </div>
  50:  </body>
  51:  </html>

我们需要引用的文件分别为

1JQUERYUI 的CSS样式文件jquery-ui-1.7.2.custom.css
2JqGrid插件的样式文件ui.jqgrid.css
3JQUERY 1.3.2的JS文件jquery-1.3.2.min.js
4JqGrid插件的中文配置文件grid.locale-cn.js
5最后是JqGrid本身的JS压缩文件jquery.jqGrid.min.js

 

Default2.aspx的功能是返回JSON数据

数据如下

{
    "page": "1",
    "total": 2,
    "records": "13",
    "rows": [
        {
            "id": "13",
            "cell": [
                "13",
                "2007-10-06",
                "Client 3",
                "1000.00",
                "0.00",
                "1000.00",
                null
            ]
        },
        {
            "id": "12",
            "cell": [
                "12",
                "2007-10-06",
                "Client 2",
                "700.00",
                "140.00",
                "840.00",
                null
            ]
        },
        {
            "id": "11",
            "cell": [
                "11",
                "2007-10-06",
                "Client 1",
                "600.00",
                "120.00",
                "720.00",
                null
            ]
        },
        {
            "id": "10",
            "cell": [
                "10",
                "2007-10-06",
                "Client 2",
                "100.00",
                "20.00",
                "120.00",
                null
            ]
        },
        {
            "id": "9",
            "cell": [
                "9",
                "2007-10-06",
                "Client 1",
                "200.00",
                "40.00",
                "240.00",
                null
            ]
        },
        {
            "id": "8",
            "cell": [
                "8",
                "2007-10-06",
                "Client 3",
                "200.00",
                "0.00",
                "200.00",
                null
            ]
        },
        {
            "id": "7",
            "cell": [
                "7",
                "2007-10-05",
                "Client 2",
                "120.00",
                "12.00",
                "134.00",
                null
            ]
        },
        {
            "id": "6",
            "cell": [
                "6",
                "2007-10-05",
                "Client 1",
                "50.00",
                "10.00",
                "60.00",
                null
            ]
        },
        {
            "id": "5",
            "cell": [
                "5",
                "2007-10-05",
                "Client 3",
                "100.00",
                "0.00",
                "100.00",
                "no tax"
            ]
        },
        {
            "id": "4",
            "cell": [
                "4",
                "2007-10-04",
                "Client 3",
                "150.00",
                "0.00",
                "150.00",
                "no tax"
            ]
        }
    ],
    "userdata": {
        "amount": 3220,
        "tax": 342,
        "total": 3564,
        "name": "Totals:"
    }
}

代码中table ID 为setcols的是用于显示数据、

代码中div ID 为psetcols的是用于显示数据下方的按钮,分页,搜索等按钮

JavaScript代码中jqGrid()方法是用于初始化JqGrid的方法

方法大概参数如下

属性名类型默认值是否必需备注
height数字150 当值为100%时会随数据的数量而自动调整高度
page数字1 当前页数
rowNum数字20 每页行数
records数字0  
pager字符串或对象 工具条所显示的容器
pgbuttons布尔值true是否显示上一页下一页的按钮
pginput布尔值true是否显示录入跳转页数的文本框
colModel数组[]定义数据列
rowList数组[]每页行数下拉选项 未设置为不显示该下拉选项
colNames数组[]显示的列名 ,需要和colModel的列数匹配
sortorder字符串"asc"排序字段的排序类型为asc和desc
sortname字符串"" 要排序列名
datatype字符串"xml"数据传递的类型一般有xml和json
mtype字符串"GET"请求的类型一般有GET和POST
altRows布尔值false设置表格是否显示斑马条纹
selarrrow数组[] 
savedRow数组[] 
shrinkToFit布尔值true 
xmlReader对象{} 
jsonReader对象{} 
subGrid布尔值false 
subGridModel数组[]  
reccount数字0  
lastpage数字0  
lastsort数字0  
selrow方法null  
beforeSelectRow方法null  
onSelectRow方法null 当选择一行时引发的事件
onSortCol方法null  
ondblClickRow方法null 当双击一行时引发的事件
onRightClickRow方法null  
onPaging方法null  
onSelectAll方法null  
loadComplete方法null  
gridComplete方法null  
loadError方法null  
loadBeforeSend方法null  
afterInsertRow方法null  
beforeRequest方法null  
onHeaderClick方法null  
viewrecords布尔值false  
loadonce布尔值false  
multiselect布尔值false  
multikey布尔值false  
editurl字符串null 添加编辑删除操作时数据提交的页面
search布尔值false是否显示搜索按钮
caption字符串""表格上方的标题,不写为不显示
hidegrid布尔值true  
hiddengrid布尔值false  
postData对象{}  
userData对象{}  
treeGrid布尔值false是否为树型GRID
treeGridModel字符串'nested'树型GRID的数据源格式一般分为nested和adjacency
treeReader对象{}  
treeANode数字-1  
ExpandColumn字符串null为树型GRID时 按钮所在的列
(在定义treeGrid情况下,指明那一列用来伸展树)
tree_root_level数字0 
prmNames对象

{page:"page",rows:"rows", sort: "sidx",order: "sord", search:"_search", nd:"nd"}

数据请求时的request的参数设定
forceFit布尔值false  
gridstate字符串

"visible"

  
cellEdit布尔值false 设置表格单元是否可以编辑
cellsubmit字符串"remote"  
nv 0  
loadui字符串"enable"  
toolbar数组[false,""]  
scroll布尔值false  
multiboxonly布尔值false  
deselectAfterSort布尔值true  
scrollrows布尔值false  
autowidth布尔值false是否自动宽度
scrollOffset数字18  
cellLayout数字5  
subGridWidth数字20  
multiselectWidth数字20  
gridview布尔值false 在工具条上是否显示总条数等信息
rownumWidth数字25  
rownumbers布尔值false  
pagerpos字符串'center'  
recordpos字符串'right'  
footerrow布尔值false  
userDataOnFooter布尔值false  
hoverrows布尔值true  
altclass字符串'ui-priority-secondary'  
viewsortcols数组[false,'vertical',true]  
resizeclass字符串''  
autoencode布尔值false  
remapColumns数组[]  
ajaxGridOptions对象{}  
direction字符串"ltr"  

先写到这里。未完。

posted @ 2009-11-29 22:18  jgjg2323 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/jgjgjg23/archive/2009/11/29/1613341.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值