views:

52

answers:

3

Hi,

I have to set the startdate/Mindate in jquery datapicked calender. i am using datepicker v1.7.2. and using mindate and max date prpperty but its not working fine.

A: 

Check this out : http://jqueryui.com/demos/datepicker/#min-max

jknair
But i want to use it for..like when user enter the start date the end date must after the start date.
Shivi
check this http://jqueryui.com/demos/datepicker/#event-search it exactly does what you are looking for
jknair
Please, see the below...problem
Shivi
@sandy doesnt make sense ???
jknair
Sorry..now its working fine..
Shivi
+1  A: 

Try this code. In this the end date is 1 day after start date.

$('#enddate').datepicker({
    dateFormat: "dd M yy",
    beforeShow: customRange,
    //Your other configurations.
    });

  function customRange(input) {
   if (input.id == "enddate")
    {
    dateMin = new Date();
    if ($("#startdate").datepicker("getDate") != null)
    {
    dateMin = $("#startdate").datepicker("getDate");
    dateMin.setDate(dateMin.getDate() + 1); //here we are adding 1 day to start date/
    }
    }
    return {
    minDate: dateMin
  }; 
}​
Alpesh
Try the above code, it should work as per your requirement.
Alpesh
Please, see the below...problem
Shivi
Sorry..now its working fine now....
Shivi
A: 

Hi,

here i am using the the "onSelect" and "beforeShow"but one of them will call at the time if i am using beforeShow then "onSelect" will not work. Please help...

afterEditCell: function (id,name,val,iRow,iCol){  

        CEditrow = iRow;
        CEditcol = iCol;
        var End_Date = jQuery("#"+iRow+"_EDate","#TaskGrid");
        var Start_Date = jQuery("#"+iRow+"_SDate","#TaskGrid");



         End_Date.datepicker({
           beforeShow: function(input, inst){
            var RowData = grid.getRowData(id);
           var Sdate = RowData.SDate;
            dateMin = new Date(Sdate);
            if (Sdate != null)
            {

            dateMin.setDate(dateMin.getDate() + 1); //here we are adding 1 day to start date/

            }
            return {
            minDate: dateMin
          }; 

           }
           });






        End_Date.datepicker({
           onSelect: function(dateText, inst) {


           var x = new Date();  
         var CurrentDate  = new Date(x.getFullYear(), x.getMonth(), x.getDate());  

           var RowData = grid.getRowData(id);

           var Status = RowData.Complete;
           var EndDate = new Date(dateText);

           var datDiff = days_between(CurrentDate,EndDate)
           var cellid = 0;

           if (EndDate >= CurrentDate && Status == 'Incomplete')
           {
             while(cellid < 8)
             {
             jQuery('#TaskGrid').setCell(id,cellid,'',{'background-color': 'red'});
             cellid++;
             }

           }
           else if(datDiff <= 5 && Status == 'Incomplete')
           {
            while(cellid < 8)
             {
             jQuery('#TaskGrid').setCell(id,cellid,'',{'background-color': 'orange'});
             cellid++;
             }          
           }
           else
           {
           while(cellid < 8)
             {
             jQuery('#TaskGrid').setCell(id,cellid,'',{'background-color': 'white'});
             cellid++;
             }    
           }   

           }
        });



        if(name=='SDate') {
                jQuery("#"+iRow+"_SDate","#TaskGrid").datepicker({dateFormat:"yy/mm/dd"});
            }

        if(name=='EDate') {
                jQuery("#"+iRow+"_EDate","#TaskGrid").datepicker({dateFormat:"yy/mm/dd"});
            }
    },


   });
Shivi