cccreator / Front

Mark And Do
0 stars 0 forks source link

JQgrid #4

Open cccreator opened 6 years ago

cccreator commented 6 years ago

JQgrid

JQgrid基本样式代码

<table id="list"></table>
<div id="pager"></div>
$("#list").jqGrid({
            url:'data/JSONData.json',//jqGrid控件通过这个参数得到需要显示的数据,具体的返回值可以是xml也可以是Json
            datatype:"json",//这个参数用于设定将要得到需要显示的数据,类型包括:json、xml、xmlstring、loca
            //colNames用于指定各列的题头文本,与列的顺序相对应
            colNames:['id','name','age'],
            //colMoel用于指定各列参数
            colModel:[
                      {name:'id',index:'id',width:200},
                      {name:'name',index:'invdate',width:200},
                      {name:'age',index:'name',width:300}
            ],
            rowNum:10,//用于设置Grid中一次显示的行数
            rowList:[10,20,30,40],//用于设置Grid可以接受的rowNum值
            pager:"#pager",//用于定义页码控制条
            sortname:'id',//指定默认的排序列,可以是列名也可以是数字。此参数会用于传递到server端
            sortorder:'desc',  //asc是升序
            mtype:"post",
            viewrecords:true,//设置是否在Pager Bar显示所有记录的总数。
            caption:"jqGrid_demo",
            recordpos:'right',
        });
        $("#list").jqGrid('navGrid','#pager',{
            add:true,
            del:true,
            edit:true,
            position:'left',
            addfunc:openDialog4Adding,
            editfunc:openDialog4Updating,
            delfunc:openDialog4Deleting,
            alerttext:"请选择需要操作的数据行!"
        });

为表格添加滚动条:shrinkToFit:false,autoScroll:true,

详细参数见此链接

cccreator commented 6 years ago

jsonReader

  1. 当repeatitems为false时
     repeatitems: false,
     jsonReader : {
         root:"rows",
         page: "page",
         total: "total",
         records: "records"
     },

json结构:

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

json中的数据可以乱序,并且允许数据空缺。jqGrid会根据colModel中的name属性和json数据对应,根据属性名称进行解析。

  1. 当repeatitems为true时,
     jsonReader : {
         root:"rows",
         page: "page",
         total: "total",
         records: "records"
     },

    json结构

    { 
      "page": "xxx", 
      "total": "yyy",
      "records": "zzz",
      "rows" : [
                   {"id" :"1", "cell" :["cell11", "cell12", "cell13"]},    // cell中不需要各列的name,但是需要与colModel一一对应
                   {"id" :"2", "cell" :["cell21", "cell22", "cell23"]},
                   ...
      ]
    }

    参考Blog

cccreator commented 6 years ago