easyui 数据行同步修改---setTimeout延迟避免出错

来源:互联网 发布:电子黑板软件下载 编辑:程序博客网 时间:2024/05/17 04:12

我在datagrid中某一列添加了一个timespinner 编辑器,打算修改spinner的时候,datagrid的另一列同步修改。

<table id="dg" class="easyui-datagrid" title="&nbsp;" style="width:100%;height:auto;"  >    <thead>    <tr>        <th data-options="field:'product_name',width:120">序号</th>        <th  data-options="field:'time_start',width:170 ">开始时间</th>        <th  data-options="field:'time_end',width:170">结束时间</th>        <th data-options="field:'time_diff',width:120,editor:{type:'timespinner',options:{required: false,showSeconds:true,highlight:1,        onSpinUp:function(){         var new_value = $(this).context.value;         planset.spinChange(new_value);        },         }}"  >调整时间</th>        <th data-options="field:'plan_name',width:150 ">计划组</th>    </tr>    </thead></table>

发现会出错,后来修正后的代码 


planset.spinChange =function(newValue){    var drow = $("#dg").datagrid("getSelected");    var row_index = $("#dg").datagrid("getRowIndex",drow);    if(!drow)return false;    drow.time_end = seagull.timespinner_add(drow.time_start,newValue).timespinner;    $('#dg').datagrid('updateRow',{        index:row_index,        row:drow,    });     $('#dg').datagrid('unselectRow',row_index);  //必须要取消选择当前行    setTimeout(function(){        $('#dg').datagrid('acceptChanges'); //才能确认修改        $('#dg').datagrid('selectRow', row_index) .datagrid('beginEdit', row_index); //再回到当前编辑器    },10); }

效果如附件