Friday, August 21, 2009

Flex calendar with putting value in datagrid

Flex code for showing calendar and getting the day, week, year of the selected day from the calendar


Through this coding you can show a calendar and get the value from the calendar and put it in the table(datagrid).


By default the current date will be selected in the calendar, if you choose some date afterwards means the date's details will be shown in the datagrid.


In the table the selected day from the calendar's values are stored like day of week, day of month, year and the full date.


     Code:
import mx.collections.ArrayCollection;
import mx.events.CalendarLayoutChangeEvent;
[Bindable]private var dateFields:ArrayCollection=new ArrayCollection();
private function useDate(calendarEvent:CalendarLayoutChangeEvent):void {
// Check whether any day is selected or not
if (calendarEvent.currentTarget.selectedDate == null) {
return
}

//Get the value from the calendar and put it in the arraycollection
var obj:Object=new Object();
obj.cal_day=calendarEvent.currentTarget.selectedDate.getDay();
obj.cal_date=calendarEvent.currentTarget.selectedDate.getDate();
obj.cal_month=calendarEvent.currentTarget.selectedDate.getMonth() + 1;
obj.cal_year=calendarEvent.currentTarget.selectedDate.getFullYear();

obj.cal_fullDate= (calendarEvent.currentTarget.selectedDate.getMonth() + 1) +
"/" + (calendarEvent.currentTarget.selectedDate.getDate() +
"/" + calendarEvent.currentTarget.selectedDate.getFullYear());
dateFields.addItem(obj);

//Refresh the datagrid after adding the object to the arraycollection
dateList.dataProvider.refresh();



Download the full code from this link download the source code
View this video for seeing how it is running


Flex Calendar View - Funny videos are here

Download the full code from this link download the source code