jQuery(function($) { var grid_selector = "#grid-table"; var pager_selector = "#grid-pager"; jQuery(grid_selector).jqGrid({ url:"/jqGrid/select.html", mtype:"get", datatype: "json", height: 250, colNames:[' ', 'ID','Last Sales','Name', 'Stock', 'Ship via','Notes'], colModel:[ {name:'myac',index:'', width:80, fixed:true, sortable:false, resize:false}, {name:'id',index:'id', width:60, sorttype:"int", editable: true}, {name:'sdate',index:'sdate',width:90, editable:true, sorttype:"date",unformat: pickDate}, {name:'name',index:'name', width:150,editable: true,editoptions:{size:"20",maxlength:"30"}}, {name:'stock',index:'stock', width:70, editable: true,edittype:"checkbox",editoptions: {value:"Yes:No"},unformat: aceSwitch}, {name:'ship',index:'ship', width:90, editable: true,edittype:"select",editoptions:{value:"FE:FedEx;IN:InTime;TN:TNT;AR:ARAMEX"}}, {name:'note',index:'note', width:150, sortable:false,editable: true,edittype:"textarea", editoptions:{rows:"2",cols:"10"}} ], rowNum:10, rowList:[10,20,30], pager : pager_selector, altRows: true, multiselect: true, //multikey: "ctrlKey", multiboxonly: true, loadComplete : function() { var table = this; setTimeout(function(){ enableTooltips(table); }, 0); }, editurl: $path_base+"/jqGrid/update.html",//nothing is saved caption: "jqGrid with inline editing", autowidth: true });
屬性css |
數據類型html |
備註jquery |
默認值json |
align數組 |
string服務器 |
left, center, right.ide |
left函數 |
classesui |
stringthis |
設置列的css。多個class之間用空格分隔,如:'class1 class2' 。表格默認的css屬性是ui-ellipsis |
empty string |
datefmt |
string |
」/」, 」-」, and 」.」都是有效的日期分隔符。y,Y,yyyy 年YY, yy 月m,mm for monthsd,dd 日. |
ISO Date (Y-m-d) |
defval |
string |
查詢字段的默認值 |
空 |
editable |
boolean |
單元格是否可編輯 |
false |
editoptions |
array |
編輯的一系列選項。{name:’__department_id’,index:’__department_id’,width:200,editable:true,edittype:’select’,editoptions: {dataUrl:」${ctx}/admin/deplistforstu.action」}},這個是演示動態從服務器端獲取數據。 |
empty |
editrules |
array |
編輯的規則{name:’age’,index:’age’, width:90,editable:true,editrules: {edithidden:true,required:true,number:true,minValue:10,maxValue:100}},設定 年齡的最大值爲100,最小值爲10,並且爲數字類型,而且爲必輸字段。 |
empty |
edittype |
string |
能夠編輯的類型。可選值:text, textarea, select, checkbox, password, button, image and file. |
text |
fixed |
boolean |
列寬度是否要固定不可變 |
false |
formoptions |
array |
對於form進行編輯時的屬性設置 |
empty |
formatoptions |
array |
對某些列進行格式化的設置 |
none |
formatter |
mixed |
對列進行格式化時設置的函數名或者類型 {name:’sex’,index:’sex’, align:’center’,width:60,editable:true,edittype:’select’,editoptions: {value:’0:待定;1:男;2:女’},formatter:function(cellvalue, options, rowObject){ |
none |
hidedlg |
boolean |
是否顯示或者隱藏此列 |
false |
hidden |
boolean |
在初始化表格時是否要隱藏此列 |
false |
index |
string |
索引。其和後臺交互的參數爲sidx |
empty |
jsonmap |
string |
定義了返回的json數據映射 |
none |
key |
boolean |
當從服務器端返回的數據中沒有id時,將此做爲惟一rowid使用只有一個列能夠作這項設置。若是設置多於一個,那麼只選取第一個,其餘被忽略 |
false |
label |
string |
若是colNames爲空則用此值來做爲列的顯示名稱,若是都沒有設置則使用name 值 |
none |
name |
string |
表格列的名稱,全部關鍵字,保留字都不能做爲名稱使用包括subgrid, cb and rn. |
Required |
resizable |
boolean |
是否能夠被resizable |
true |
search |
boolean |
在搜索模式下,定義此列是否能夠做爲搜索列 |
true |
searchoptions |
array |
設置搜索參數 |
empty |
sortable |
boolean |
是否可排序 |
true |
sorttype |
string |
用在當datatype爲local時,定義搜索列的類型,可選值:int/integer - 對integer排序float/number/currency - 排序數字date - 排序日期text - 排序文本 |
text |
stype |
string |
定義搜索元素的類型 |
text |
surl |
string |
搜索數據時的url |
empty |
width |
number |
默認列的寬度,只能是象素值,不能是百分比 |
150 |
xmlmap |
string |
定義當前列跟返回的xml數據之間的映射關係 |
none |
unformat |
function |
‘unformat’單元格值 |
null |
jqGrid爲其設了默認值
jsonReader : { root: "rows",//返回的數組集合 page: "page",//當前頁數 total: "total", //總頁數 records: "records",//總行數 repeatitems: true,//指明每行的數據是能夠重複的,若是設爲false,則會從返回的數據中按名字來搜索元素 cell: "cell", id: "id", userdata: "userdata", //咱們須要用的一些並不想顯示到頁面上的數據 //下面通常不用 subgrid: {root:"rows", //是否使用suggrid模型 repeatitems: true, cell:"cell" }
,設置jqGrid將要向Server傳遞的參數名稱。其默認值爲:
prmNames : {
page:"page", // 表示請求頁碼的參數名稱
rows:"rows", // 表示請求行數的參數名稱
sort: "sidx", // 表示用於排序的列名的參數名稱
order: "sord", // 表示採用的排序方式的參數名稱
search:"_search", // 表示是不是搜索請求的參數名稱
nd:"nd", // 表示已經發送請求的次數的參數名稱
id:"id", // 表示當在編輯數據模塊中發送數據時,使用的id的名稱
oper:"oper", // operation參數名稱
editoper:"edit", // 當在edit模式中提交數據時,操做的名稱
addoper:"add", // 當在add模式中提交數據時,操做的名稱
deloper:"del", // 當在delete模式中提交數據時,操做的名稱
subgridid:"id", // 當點擊以載入數據到子表時,傳遞的數據名稱
npage: null,
totalrows:"totalrows" // 表示需從Server獲得總共多少行數據的參數名稱,參見jqGrid選項中的rowTotal
}