jqGrid的editrules参数

原文链接: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的值,强烈推荐为所有的其他编辑元素都设置这些值。

 

posted @ 2017-08-07 17:56  单纯的桃子  阅读(382)  评论(0编辑  收藏  举报