項目出現一個需求,要求用戶界面的用戶名,新增時,可自由輸入,編輯時,不可修改
html頁面
<table id="gridlist" data-bind="datagrid:grid" > <thead> <tr> <th field="ck" checkbox="true" readOnly:true ></th> <th field="OptimisticLockField" hidden="true"></th> <th field="UserCode" sortable="true" align="left" width="80" editor="{type:'validatebox',options:{required: true }}" >用戶名 </th> <th field="UserName" sortable="true" align="left" width="200" editor="{type:'validatebox',options:{required: true }}" >名稱 </th> <th field="OriginalPassword" sortable="true" align="left" width="200" >密碼 </th> <th field="Org" sortable="true" align="left" width="200" editor="{type:'lookup',options:{required:true,lookupType:'cloud.PcsOrg',window:{title:'所屬機構'},queryParams:{State:9,Ou:false}}}" formatter="formatOrg" >所屬機構 </th> <th field="IsEnable" sortable="true" align="center" width="120" editor="{type:'checkbox',options:{on:1,off:0}}" formatter="com.formatCheckbox" >是否可用</th> <th field="IsAdmin" align="center" width="120" editor="{type:'checkbox',options:{on:1,off:0}}" formatter="com.formatCheckbox">是否管理員</th> <th field="LoginCount" sortable="true" align="right" width="120" >登錄次數</th> <th field="LastLoginDate" sortable="true" align="left" width="135" formatter="com.formatDate">最后登錄日期</th> <th field="LastLoginOU" align="left" width="170" hidden="true" >最后登錄組織</th> <th field="OrganizeNames" align="left" width="170">最后登錄組織</th> <th field="Permit" align="center" width="320" formatter="formatterButton"> 操作 </th> <th field="Description" align="left" width="150" editor="text">描述</th> </tr> </thead> </table>
原先編輯方法
//原先編輯方法 this.editClick = function () { if (self.RowsCount() > 1) return; var row = self.grid.datagrid('getSelected'); if (row == null) { com.message('error', "請選中需編輯的一行數據"); return; } var index = self.grid.datagrid('getRowIndex', row); self.gridEdit.begin(index, row); self.viewType = v_edit; self.IsViewType(v_edit); };
新的編輯方法
//新的編輯方法 this.editClick = function () { if (self.RowsCount() > 1) return; var row = self.grid.datagrid('getSelected'); if (row == null) { com.message('error', "請選中需編輯的一行數據"); return; } //在編輯后把用戶名改為查看狀態 if (row._isnew == undefined) { //編輯的時候把用戶名改為查看狀態 $('#gridlist').datagrid('removeEditor', 'UserCode'); } var index = self.grid.datagrid('getRowIndex', row); self.gridEdit.begin(index, row); self.viewType = v_edit; self.IsViewType(v_edit); };
頁面效果
1)新增時
2)編輯時
總結:使用 datagrid的removeEditor方法,指定對應列名,如語法: $('#gridlist').datagrid('removeEditor', 'UserCode');