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>