jqgrid - 根据以前的列值

时间:2017-08-02 14:35:23

标签: jqgrid

我正在使用jquery.maskedinput-1.3.js

在第1列中,是手机类型。第2栏中的电话号码。

{name:'PhoneTypeId',index:'PhoneTypeId',hidden:true,editable:true,sortable:true},

{name:'Phone',index:'Phone',width:150,editable:true,editoptions:{dataInit:function(elem){$(elem).mask(“(999)999-9999”) ; },dataEvents:[{type:'change',fn:function(e){hasChanges = true}}]},editrules:{required:true},sortable:true},

我想根据手机的类型动态更改遮罩。这可能吗?

我的数据是json序列化对象:         数据类型:“local”,         数据:@ Html.Raw(ViewBag.Phones)         editurl:'clientArray'

谢谢, 根

1 个答案:

答案 0 :(得分:0)

You can add change event (using dataInit) of the phone type and based on this you can change the mask (if this plugin allows this). Initially when you start editing (depending on the edit type - form edit or inline edit) you can use some events before editing by example beforeShowForm for form edit or beforeEditRow for inline edit. If you use Guriddo jqGrid JS you can look at the documentation here

EDIT:

In case the field phonetype is not editable by the user then

{ name: 'Phone', index: 'Phone', width: 150, editable: true, 
    editoptions:{ 
        dataInit: function (elem, options) { 
           // use the id of the row
           var id = options.rowId;
           // content of the phonetype cell
           var phonetypeval = $(this).jqGrid('getCell', id, 'PhoneTypeId')
           if( phonetypeval === 'something') {
               mask = 'mask1';
           } else {
               mask = 'mask2';
           }
           $(elem).mask(mask); 
        }, 
        dataEvents: [{
            type: 'change', fn: function (e) { hasChanges=true } }
        ]}
    , editrules:{required: true}, 
    sortable: true}

Note that this code is valid for inline and form edit.