jqGrid|初始化|参数
名称 | 描述 |
---|---|
url | 获取数据地址 |
datatype | 从服务器端返回的数据类型,默认为xml。可选类型有:xml,local,json等。 |
mtype | ajax提交方式,POST或者GET。默认GET。 |
colNames | 列显示名称,是一个对象数组。 |
colModel | 常用到的属性:name:列显示的名称; index:传到服务器端用来排列用的列名称;width:列宽度;align:对齐方式;sortable:是否可以排序; |
pager | 定义翻页用的导航栏,必须是有效的html元素。翻页工具可以放在页面的任意位置。 |
rowNum | 在grid上显示记录条数,这个参数要被传递到后台。 |
rowList | 一个下拉选择框,用来改变显示记录数,当选择时会覆盖rowNum参数传递到后台。 |
viewrecords | 定义是否要显示总记录数 |
caption | 表格名称 |
direction | 表格中文字的显示方向,从左向右(ltr)或者从右向左(rtl) |
editurl | 定义对form编辑时的url |
height | 表格高度,可以是数字,像素值或者百分比 |
prmNames | Default valuesprmNames: {page:“page”,rows:“rows”, sort: “sidx”,order: “sord”, search:“_search”, nd:“nd”, npage:null} 当参数为null时不会被发到服务器端 |
jqGrid colModel 参数
ColModel 是jqGrid里最重要的一个属性,设置表格列的属性。
属性 | 描述 |
---|---|
align | 对齐方式。可选:left,center,right; |
classes | 设置列的css。多个class之间用空格分隔,如:‘class1 class2’。表格默认的css属性是ui-ellipsis。 |
datefmt | “/”,“-”,“.”都是有效的日期分隔符。日期格式,string Y-m-d |
editable | 单元格是否可编辑 |
editoptions | 编辑的一系列选项。{name:‘goodsId’, index:‘goodsId’, width:200, editable:true, edittype:‘select’, editoptions:{dataUrl:“goods_goodsEdit.do”}}。动态从服务器端获取数据的例子。 |
editrules | 编辑的规则{name:‘age’, index:‘age’, width:90, editable:true, editrules:{edithidden:true, required:true, number:true, minValue:10, maxValue:100}},设定年龄的最大值为100,最小值为10,而且为数字类型,并且必输字段。 |
fixed | 列宽度是否要固定不可变 |
formoptions | 对于form进行编辑时的属性设置 |
formatoptions | 对某些列进行格式化的设置 |
formatter | 对列进行格式化时设置的函数名或者类型。 {name:‘sex’, index:‘sex’, align:‘center’, width:60, editable:true, edittype:‘select’, editoptions:{value:‘0:待定;1:男;2:女’}, formatter:function(cellvalue, options, rowObject){ var temp = “<img src = ‘./img/” if (cellvalue == 1) { temp = temp + “male.png”; } else if (cellvalue == 2) { temp = temp + “female.png”; } else { temp = temp + “user.png”; } temp = temp + “ ‘border = ‘ 0’/> “ return temp; }}, //返回性别的图标 |
hidden | 在初始化表格时是否要隐藏此列。 |
index | 索引。其和后台交互的参数是sidx |
label | 如果colNames为空则用此值来作为列的显示名称,如果都没有设置则使用name值。 |
name | 表格列的名称,所有关键字、保留字都不能作为名称使用,包括subgrid,cb,rn |
sortable | 是否可排序 |
sorttype | 用在当datatype为local时,定义搜索列的类型,可选值:int/integer,对integer排序; float/number/currency,排序数字; date:排序日期; text:排序文本。 |
width | 默认列的宽度,只能是像素值,不能使百分比 |
unformat | ‘unformat’单元格值 |
edittype | 可编辑的类型。可选值:text, textarea, select, checkbox, password, button, image, file。 |