2013-07-25 61 views
0

我在內聯編輯之後和保存數據之前檢查單元格值時遇到問題。我的ColModel的一部分是(沒有任何非民族代碼):在發佈數據到服務器之前檢查單元格值

{name:'event_start_date',index:'event_start_date',width:75,align:'center',editable:true,edittype:'text',editoptions:{size:'10',maxlength:'10', 
     dataInit:function(el){ 
     $(el).mask('9999-99-99'); 
     $(el).datepicker({dateFormat:'yy-mm-dd', 
      beforeShow: function(input, instance){instance.dpDiv.css({marginTop: '1px'});}}) 
     }} 
    }, 
    {name:'event_start_time',index:'event_start_time',width:70,align:'center',editable:true,edittype:'text',editoptions:{size:'8',maxlength:'8', 
     dataInit:function(el){$(el).mask('99:99:99');}} 
    }, 
    {name:'event_end_date',index:'event_end_date',width:75,align:'center',editable:true,edittype:'text',editoptions:{size:'10',maxlength:'10', 
     dataInit:function(el){ 
     $(el).mask('9999-99-99'); 
     $(el).datepicker({dateFormat:'yy-mm-dd', 
      beforeShow: function(input, instance){instance.dpDiv.css({marginTop: '1 px'});}}) 
     }} 
    }, 
    {name:'event_end_time',index:'event_end_time',width:70,align:'center',editable:true,edittype:'text',editoptions:{size:'8',maxlength:'8', 
     dataInit:function(el){$(el).mask('99:99:99');}} 
    }, 
    {name:'event_dur_calc',index:'event_dur_calc',width:90,align:'center',editable:false,edittype:'text',sorttype:'date',editoptions:{size:'10',maxlength:'10'} 
    } 

我正在使用雙擊進入內聯編輯模式。用戶後做出一些改變成日期/時間字段,用於細胞「event_dur_calc」計算出新的價值:

$('#'+rowId+'_event_start_date').focusout(function(){recalc_dur(rowId);}); 
$('#'+rowId+'_event_start_time').focusout(function(){recalc_dur(rowId);}); 
$('#'+rowId+'_event_end_date').focusout(function(){recalc_dur(rowId);}); 
$('#'+rowId+'_event_endt_time').focusout(function(){recalc_dur(rowId);}); 

功能FO計算新的時間:

function mktime(){ 
    var i = 0, d = new Date(), argv = arguments, argc = argv.length; 
    var dateManip = { 
    0: function(tt){ return d.setHours(tt); }, 
    1: function(tt){ return d.setMinutes(tt); }, 
    2: function(tt){ return d.setSeconds(tt); }, 
    3: function(tt){ return d.setMonth(parseInt(tt)-1); }, 
    4: function(tt){ return d.setDate(tt); }, 
    5: function(tt){ return d.setYear(tt); } 
    }; 
    for(i = 0; i < argc; i++){ 
    if(argv[i] && isNaN(argv[i])){ 
     return false; 
    } else if(argv[i]){ 
     if(!dateManip[i](argv[i])){ 
     return false; 
     } 
    } 
    } 
    return Math.floor(d.getTime()/1000); 
}; 

function recalc_dur(rowId){ 
    var event_start_date_txt = $('#'+rowId+'_event_start_date').val(); 
    var event_start_time_txt = $('#'+rowId+'_event_start_time').val(); 
    var event_end_date_txt = $('#'+rowId+'_event_end_date').val(); 
    var event_end_time_txt = $('#'+rowId+'_event_end_time').val(); 

    if (event_end_date_txt=='0000-00-00'){ 
    $('#'+rowId+'_event_dur_calc').val('0000:00:00'); 
    }else{ 
    var start_d_pices = event_start_date_txt.split('-'); 
    var start_t_pices = event_start_time_txt.split(':'); 
    var end_d_pices = event_end_date_txt.split('-'); 
    var end_t_pices = event_end_time_txt.split(':'); 
    var start_time = mktime(start_t_pices[0], start_t_pices[1], start_t_pices[2], start_d_pices[1], start_d_pices[2], start_d_pices[0]); 
    var end_time = mktime(end_t_pices[0], end_t_pices[1], end_t_pices[2], end_d_pices[1], end_d_pices[2], end_d_pices[0]); 
    var delta = end_time-start_time; 
    var secs = delta % 60; 
    delta = (delta - secs)/60; 
    if (secs.toString().length==1) var new_dur = ':0'+secs; else var new_dur = ':'+secs; 
    var mins = delta % 60; 
    delta = (delta - mins)/60; 
    if (mins.toString().length==1) new_dur = ':0'+mins+new_dur; else new_dur = ':'+mins+new_dur; 
    var hours = delta; 
    if (hours.toString().length==1){new_dur = '000'+hours+new_dur; 
    }else if (hours.toString().length==2){new_dur = '00'+hours+new_dur; 
    }else if (hours.toString().length==3){new_dur = '0'+hours+new_dur; 
    }else new_dur = hours+new_dur; 
    $('tr[id=\"'+rowId+'\"] > td[aria-describedby=\"dfr_event_dur_calc\"]').html(new_dur); 
    } 
} 

如果新的計算時間將低於零(當開始日期/時間大於結束日期/時間時),出現帶警告消息的模式窗口,數據不能保存併發布到服務器上。

在發佈數據之前是否有任何事件在內聯編輯模式下觸發,我可以使用它來檢查新的計算值以防止不正確的數據被保存?

回答

0

jqGrid的當前代碼github包含beforeSaveRow回調函數,它將在保存之前調用。在發佈jqGrid 4.5.2之後,更改爲,但該功能將存在於jqGrid的下一個版本(> 4.5.2)中。因此,如果您不想使用來自github的開發人員源,則可以使用標準驗證方式:使用editrulescustom: truecustom_func進行驗證。

相關問題