1. 程式人生 > >jqGrid的editrules參數

jqGrid的editrules參數

eas turn 之前 tex val 是否 推薦 參數 article

原文鏈接:http://blog.csdn.net/mengtianyalll/article/details/13502841

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”]這樣。

例如:

1  function mypricecheck(value, colname) {
2         if (value < 0 && value >20) 
3            return [false,"Please enter value between 0 and 20"];
4         else 
5            return [true,""];
6 }

1   colModel: [
2                                 { label: ‘主鍵‘, name: ‘Id‘, hidden: true
}, 3 { label: ‘工藝編碼‘, name: ‘PPRCode‘, hidden: true }, 4 { label: ‘工序編碼‘, name: ‘Code‘, width: 80, align: ‘left‘ }, 5 { label: ‘工序名稱‘, name: ‘Name‘, width: 80, align: ‘left‘ }, 6 { label: ‘是否剔除‘, name: ‘IsRemoved‘, width: 80, align: ‘left‘, editable: true
, edittype: "checkbox", editoptions: { value: "是:否" } }, 7 { label: ‘序列號‘, name: ‘OrderIndex‘, width: 80, align: ‘left‘, editable: true, editrules: { edithidden: true, required: true, number: true } }, 8 { label: ‘備註‘, name: ‘Describe‘, width: 200, align: ‘left‘ } 9 ],

上面是我項目中用到的

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的值,強烈推薦為所有的其他編輯元素都設置這些值。

jqGrid的editrules參數