问题
I have been able to work the Date Picker into JQGrid when editing inline, but I am unable to use it inside the add/edit window. Does anyone have instructions on how to do this or an example I can look at?
demo from that site of what I am trying to do: http://www.the-di-lab.com/demo/apples
I read that I could use the following method but not sure how to integrate it:
dataInit : function (elem) {
$(elem).datepicker();
}
回答1:
It looks like they are using 'afterShowForm' to attach a date/color picker to a div.
(view source)
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(); } },
(view source)
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); } });
Thanks for finding this example, I was looking for how to do this as well.
回答2:
Adding datepicker is an easy task:
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 ...
]
Of couse, instead of .datepicker
you can use any plugin like colorpicker or autocomplete.
回答3:
Use this code to add datepicker to create/edit dialog:
.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")
}
},
...
来源:https://stackoverflow.com/questions/1246329/jqgrid-date-picked-within-add-edit-window