2013-11-20 30 views
0

我有JSP頁面,其中有選項卡。每個選項卡加載一個jqgrid(在所有三個選項卡中加載相同的JSP)。我在jqgrid和日期字段中使用了日期選擇器。jquery datepicker問題與jquery選項卡和jqgrid

的日期選擇器工作在第一個選項卡罰款,但是當我嘗試打「上一個」 /「下一步」,在它跳躍到1900年。參考下面圖片等選項卡日期選擇器:

日期選擇器按預期工作在第一個選項卡: enter image description here

日期選擇器跳轉到1899年在創下第二個選項卡上一篇: enter image description here

我試着調試代碼裏面的jQuery-UI-1.10.0.custom.js

/* Adjust one of the date sub-fields. */ 
_adjustDate: function(id, offset, period) { 
    var target = $(id), 
     inst = this._getInst(target[0]); 
    console.dir(inst); 
    if (this._isDisabledDatepicker(target[0])) { 
     return; 
    } 
    this._adjustInstDate(inst, offset + 
     (period === "M" ? this._get(inst, "showCurrentAtPos") : 0), // undo positioning 
     period); 
    this._updateDatepicker(inst); 
}, 

我得到了兩種情況下的輸出如下:

第一個標籤:

LOG: { 
    id : "gs_vpReportDate", 
    input : [object Object], 
    selectedDay : 20, 
    selectedMonth : 10, 
    selectedYear : 2013, 
    drawMonth : 10, 
    drawYear : 2013, 
    inline : false, 
    dpDiv : [object Object], 
    settings : [object Object], 
    append : [object Object], 
    trigger : [object Object], 
    lastVal : "", 
    currentDay : 0, 
    currentMonth : 0, 
    currentYear : 0, 
    yearshtml : null, 
    _keyEvent : false 
} 

第二個選項卡:

LOG: { 
    id : "gs_vpReportDate", 
    input : [object Object], 
    selectedDay : 0, 
    selectedMonth : 0, 
    selectedYear : 0, 
    drawMonth : 0, 
    drawYear : 0, 
    inline : false, 
    dpDiv : [object Object], 
    settings : [object Object], 
    append : [object Object], 
    trigger : [object Object] 
} 

任何想法,爲什麼這種怪異的行爲?

附加信息: 該ID是動態分配的。

下面是我的jqGrid列:

{ name: 'vpReportDate', index: 'vpReportDate',datefmt:"m/d/Y", sorttype:"date", width: 65, searchoptions:{dataInit:showDatePicker}, sortable:true } 

function showDatePicker(elem) { 
    $(elem).datepicker({dateFormat:'mm/dd/yy', changeYear: true, changeMonth: true}).change(function() { 
     $("#dasWorkQueueGrid_" + activeTabId)[0].triggerToolbar(); 
    }); 
}; 
+0

是否有可能給每個日曆例如在每個標籤不同的ID?可能是衝突 – geedubb

+0

@geedubb ID是動態分配的。 以下是我的jqgrid列: 'code'{name:'vpReportDate',index:'vpReportDate',datefmt:「m/d/Y」,sorttype:「date」,width:65,searchoptions:{dataInit:showDatePicker },可排序:真} \t功能showDatePicker(ELEM){ \t \t $(ELEM).datepicker({DATEFORMAT: 'MM/DD/YY',changeYear:真,changeMonth:真})。變化(函數( ){ \t \t \t $( 「#dasWorkQueueGrid_」 + activeTabId)[0] .triggerToolbar(); \t \t}); \t}; – tarares

+0

請修改您的問題以包含其他信息 – geedubb

回答

0

我找到了解決我的問題。這個問題的根本原因在於當網格加載到第二個選項卡上時,第一個網格已經存在於DOM中,並且導致了所有問題。因此,我所做加載前柵格我打電話gridDestroy銷燬所有存在於DOM的網格 -

$("[id^=dasWorkQueueGrid_]").jqGrid('GridDestroy'); 
  • 我使用jQuery選擇通配符來識別所有的網格。

,然後加載網:

$("#dasWorkQueueGrid_" + activeTabId).jqGrid({ 
    *** Grid Code *** 
    });