PDA

View Full Version : Adding month to datepicker dynamically



pavani
8 Aug 2012, 5:55 AM
Hi,

Iam new to ext js . I want to add my month, year and date to date picker based on the values comes from json object.
for example my jsonObject is liike this,
{data:[{year:2030},{month:November},{date:24}]}

Then on page load i should show these values in date picker instead of currentMonth, currentDate and currentYear

sword-it
8 Aug 2012, 7:14 AM
Hi pavani,
I am giving you a demo example. In this example I have taken one button, on the click of that button I set the value of date picker according to you dateobject. Review the following code:



Ext.create('Ext.panel.Panel', {
title: 'Choose a future date:',
width: 200,
bodyPadding: 10,
renderTo: Ext.getBody(),
items: [
{
xtype: 'datepicker',
minDate: new Date()
},
{
xtype: 'button'
, text: 'change date'
, handler: function(btn){
var myDate = {data:[{year:2030},{month:'November'},{date:24}]} // getting you date object
, data = myDate.data // getting the data value
, dateObj = {};
for(var i=0,totalItems=data.length;i<totalItems;i++){
Ext.apply(dateObj, data[i]); // having different objects in one obj
}
// in below I am creating the date with you date object
var newDate = new Date(dateObj.month + '/'+ dateObj.date + '/'+ dateObj.year);
this.prev().setValue(newDate); //setting the datepicker value with the date object
}
}
]
});