注意datagrid使用的触发函数是:
onBeginEdit,只有在这个触发条件下,editor才真正初始化完成,不然没法动态修改numberbox中的最大最小值。
示例代码:(注意这一块:onBeginEdit:changeNumberMax)
<table id="dg" style="960px;height:auto" data-options=" singleSelect: true, url: '<%=request.getContextPath() %>/settlementRule/relatedServices?prodId=${productDto.prodId }', method:'get', onLoadSuccess:checkData, onBeginEdit:changeNumberMax "> <thead> <tr> <th data-options="field:'id',150,hidden:true">规则ID</th> <th data-options="field:'createTime',150,hidden:true">规则创建时间</th> <th data-options="field:'prodSrvId',150,hidden:true">服务ID</th> <th data-options="field:'srvName',150">服务名称</th> <th data-options="field:'srvCode',150">服务编号</th> <th data-options="field:'providerName',150">所属厂商</th> <th data-options="field:'srvTypeDesc',108">服务类型</th> <th data-options="field:'rate',100,formatter:function(value,row){if(value!=null&&value!=0) {return value+'%';}}">分摊比例</th> <th data-options="field:'ruleType',150,formatter:function(value,row){if(value==${FIXED_ACCOUNT_SETTLEMENT}) {return '固定金额结算'} else if(value==${PROPORTION_SETTLEMENT}) { return '按比例结算'} }, editor:{type:'combobox',options:{url: '<%=request.getContextPath() %>/settlementRule/getSettlementRuleTypeEnums',valueField:'enumEntryValue',textField:'enumEntryLabel', method:'get',editable:'true',panelHeight: 'auto',required:'true',editable:false}}">结算类型</th> <th data-options="field:'val',150,formatter:function(value,row){if(value!=null){if(row.ruleType==${PROPORTION_SETTLEMENT}) {return value+'%';} else if(row.ruleType==${FIXED_ACCOUNT_SETTLEMENT}) {return value;}}},editor:{type:'numberbox',options:{required:'true',min:0,precision:2}}">结算规则</th> </tr> </thead> </table>
相应的触发函数:
function changeNumberMax(rowIndex,rowData) { var ruleType=rowData.ruleType; if(ruleType==0) { var sharePercent=rowData.rate; var ed = $('#dg').datagrid('getEditor', {index:rowIndex,field:'val'}); $(ed.target).numberbox({ max: ${productDto.prodPrice }*sharePercent/100, precision: 2, min:0 }); } }