6

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();
}
Jason Plank
  • 2,336
  • 5
  • 31
  • 40
kilrizzy
  • 2,895
  • 6
  • 40
  • 63
  • The main thing is to set z-index for datepicker. See [this][1]. [1]: http://stackoverflow.com/questions/715677/trouble-with-jquery-dialog-and-datepicker-plugins/715695#715695 –  Aug 23 '11 at 16:47

3 Answers3

16

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.

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
3

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.

dwright
  • 504
  • 3
  • 7
  • Thank you, it is slowly coming together, the jsrs code is being triggered when the window opens but I am just getting the "$("#appointment").DatePicker is not a function" (I changed the instances of #date to #appointment since that is the id of the desired field) All the needed scripts/ui are there to get it working outside of the popup, Is there something I need to do that I might be missing? Thank You!! – kilrizzy Aug 20 '09 at 18:06
  • Oh I just needed "datepicker" instead of "DatePicker" THANKS! – kilrizzy Aug 20 '09 at 18:11
1

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")
                    }
                },
                ...
katrin
  • 1,146
  • 1
  • 13
  • 24