2009-08-07 82 views
6

在内联编辑时,我已经能够将日期选取器工作到JQGrid中,但我无法在添加/编辑窗口中使用它。有没有人有指导如何做到这一点或我可以看看的例子? http://www.the-di-lab.com/demo/applesJQGrid /添加/编辑窗口中选择的日期

我读,我可以用下面的方法,但不知道如何将它集成:

dataInit : function (elem) { 
$(elem).datepicker(); 
} 
+0

最主要的是设置的z-index的日期选择器。看[这] [1]。 [1]:http://stackoverflow.com/questions/715677/trouble-with-jquery-dialog-and-datepicker-plugins/715695#715695 – 2011-08-23 16:47:31

回答

3

看起来他们是从什么,我试图做的是网站

演示使用'afterShowForm'将日期/颜色选择器附加到div。
(查看源代码)

 
jQuery("#list").navGrid("#pager",{edit:true,add:true,del:true}, 
        {width:400,height:400,closeAfterEdit:true, 
      afterShowForm:function(){ $("#jsrs").load("/demo/apples/jsrs"); }, 
      onclickSubmit:function() { $("#jsrs").empty(); } 
}, 

(查看源代码)

 
http://www.the-di-lab.com/demo/apples/jsrs 

//Js for colorPicker 
$('#color').ColorPicker({ 
    onSubmit: function(hsb, hex, rgb) { 
     $('#color').val("#"+hex); 
    }, 
    onBeforeShow: function() { 
     $(this).ColorPickerSetColor(this.value); 
    } 
}).bind('keyup', function(){ 
    $(this).ColorPickerSetColor(this.value); 
}); 


//Js for datePicker 
$('#date').DatePicker({ 
    format:'Y-m-d', 
    date: $('#date').val(), 
    current: $('#date').val(), 
    starts: 1, 
    position: 'bottom', 
    onBeforeShow: function(){ 
     $('#date').DatePickerSetDate($('#date').val(), true); 
    }, 
    onChange: function(formated, dates){ 
     $('#date').val(formated); 
    } 
    }); 

感谢发现这个例子中,我一直在寻找如何做到这一点。

+0

谢谢,慢慢走到一起时,当窗口打开时,jsrs代码被触发,但我刚刚得到“$(”#appointment“)。DatePicker不是函数”(我将#date的实例更改为#appointment,因为这是所需字段的ID ) 所有需要的脚本/ UI都可以在弹出窗口外工作,有什么我需要做的,我可能会失踪?谢谢!! – kilrizzy 2009-08-20 18:06:20

+0

哦,我只需要“datepicker”而不是“DatePicker”,谢谢! – kilrizzy 2009-08-20 18:11:54

15

添加日期选择是一件容易的事:

colModel: [ 
    ... other column definitions ... 
    { 
    name:'my_date', index:'my_date', label: 'Date', width: 80, 
    editable: true, edittype: 'text', 
    editoptions: { 
     size: 10, maxlengh: 10, 
     dataInit: function(element) { 
     $(element).datepicker({dateFormat: 'yy.mm.dd'}) 
     } 
    } 
    }, 
    ... other column definitions ... 
] 

淡然,取而代之的.datepicker你可以使用任何插件,像颜色拾取或自动完成。

+0

-1,您在那里有几个错误...并且在修复错误之后,代码似乎不起作用 – Fragsworth 2010-03-16 18:35:47

+0

+1,感谢您指出'editoptions.dataInit';这是缺少让我的内联编辑工作的一块。 – 2011-03-25 21:48:59

+0

辉煌。适合我! – AnonyMouse 2011-10-09 22:20:12

1

使用此代码添加日期选择器创建/编辑对话框:

.navGrid('#yourID', 
       { edit: true, add: true, del: true, search: true }, //options 
       { 
        ... 
        onInitializeForm: function() { 
         $('#yourDate').datepicker(); 
        }, 
        onClose: function() { 
         //if you close dialog when the datepicker is shown 
         $('.hasDatepicker').datepicker("hide") 
        } 
       }, 
       ... 
+0

这工作非常好 – Cruachan 2011-08-02 19:19:04

相关问题