以下為內容留存記錄。
editrules
editrules是用來設置一些可用於可編輯列的colModel的額外屬性的。大多數的時候是用來在提交到服務器之前驗證用戶的輸入合法性的。比如editrules:{edithidden:true, required:true....}。
可選的屬性包括:
edithidden:只在Form Editing模式下有效,設置為true,就可以讓隱藏字段也可以修改。
required:設置編輯的時候是否可以為空(是否是必須的)。
number:設置為true,如果輸入值不是數字或者為空,則會報錯。
integer:
minValue:
maxValue:
email:
url:檢查是不是合法的URL地址。
date:
time:
custom:設置為true,則會通過一個自定義的js函數來驗證。函數定義在custom_func中。
custom_func:傳遞給函數的值一個是需要驗證value,另一個是定義在colModel中的name屬性值。函數必須返回一個數組,一個是驗證的結果,true或者false,另外一個是驗證錯誤時候的提示字符串。形如[false,”Please enter valid value”]這樣。
自定義驗證的例子:
<script>
function mypricecheck(value, colname) {
if (value < 0 && value >20)
return [false,"Please enter value between 0 and 20"];
else
return [true,""];
}
jQuery("#grid_id").jqGrid({
...
colModel: [
...
{name:'price', ..., editrules:{custom:true, custom_func:mypricecheck....}, editable:true },
...
]
...
});
</script> < function mypricecheck(value, colname) { if (value < 0 && value >20) return [false,"Please enter value between 0 and 20"]; else return [true,""]; } jQuery("#grid_id").jqGrid({ ... colModel: [ ... {name:'price', ..., editrules:{custom:true, custom_func:mypricecheck....}, editable:true }, ... ] ... }); // >
formoptions(只在Form Editing方式下有效),他的主要作用是用來重新排序Form中的編輯元素,同時可以在編輯元素前或者編輯元素后增加一些信息(比如,一些提示信息,或者一個紅色的*表示必須要填寫等等)。
可選的屬性如下:
elmprefix:字符串值,如果設置了,則會在編輯框之后出現一些內容(可能是HTML的內容)
elmsuffix:字符串值,如果設置了,則會在編輯框之前出現一些內容(可能是HTML的內容)
label:字符串值,如果設置了,則這個值會替換掉colNames中的值出現作為該編輯框的標簽顯示
rowpos:數字值,決定元素行在Form中的位置(相對於文本標簽again with the text-label)
colpos:數字值,決定元素列在Form中的位置(相對於標簽again with the label)
兩個編輯框可以有相同的rowpos值,但是colpos值不同,這會把這兩個編輯框放到Form的同一行中。
特別注意:如果設置了rowpos以及colpos的值,強烈推薦為所有的其他編輯元素都設置這些值。