datagrid 的2个问题

1)对datagrid的某个栏位值使用下拉方式   

 <th data-options="field:'UserId',width:100,
                        formatter: unitformatter,
                        editor:{
                            type:'combobox',
                            options:{
                                valueField:'UserId',
                                textField:'userName',
                                url:'../../manager.ashx?act=GetMgr&plantNo='+plantNo,
                                required:true,
                                onSelect: function (record) {                                
                                    $('#dg').datagrid('getRows')[editIndex]['userName']=record.userName;
                                }
                            }   
                        }               
                        ">主管名字</th>

 这个是对该栏位使用ajax的方式得到值来填充。

但是这次使用的比较简单,我们的选项是固定的(本来想放到数据库中,感觉没有必要了,先直接放到页面上可选算了)

结果还发现赋值很难找到诀窍,网上找到的东西都是语焉不详的,花了我2个小时时间,最终搞定结果如下。

<th data-options="field:'Reason',width:80,align:'left'
                        ,editor:{
                            type:'combobox',
                            options:{
                                valueField:'text',
                                textField:'text',
                                data: Reasons,
                                required:true                               
                            }   
                        }           
                        ">超領原因</th>

---Javascript定义全局变量Reasons;
var Reasons; Reasons = $.parseJSON('[{ "text": "作業損耗" }, { "text": "機器異常" }, { "text": "其它" }]');

2)对datagrid的某个栏位值设定为必输栏位

上面有对combobox 设定必输,但是我需要对几个"text" 设定必输,网上的资料也是不详细,很多人说直接加" options:{required:true}“就可以了,

可是加了也是不起作用的,都准备放到endEdit里面进行处理了,最后终于灵光一闪,发现了一个问题,修改Type就可以了。

<th data-options="field:'PartNo',width:160,align:'left',editor:{type:'validatebox',options:{required:true}}">料號</th>

 万事大吉了,数字类型的栏位可以直接加限制就OK了。

                   <th data-options="field:'Qty',width:40,align:'left',editor:{type:'numberbox',options:{required:true}}">數量</th>

  

 

猜你喜欢

转载自www.cnblogs.com/wonder223/p/9940102.html