Reputation: 14108
Goal:
Display specified date in the datepicker based on available date from the database.
For example, I have date "2015-04-30", "2015-05-15", and "2015-05-16" in the database and these three date should only displayed in the datepicker (https://jqueryui.com/datepicker/).
Question:
I tried to find any solution but I failed. I don't know what to do?
Information:
*I retrieve the dates' value as a string "150430". The default value I retrieve is datetype datetime. Totally, it is two different parameter.
*https://jqueryui.com/datepicker/
*I'm using ASP.net MVC and Bootstrap
Upvotes: 1
Views: 229
Reputation: 17064
Taken from the documentation:
So you can basically do this:
var availableDates = ["30-4-2015","15-5-2015","16-5-2015"];
$('#datePicker').datepicker({
beforeShowDay: isDateAvailabele
});
And construct the function to return [true, "", ""]
or [false, "", ""]
depending if the date is to be presented.
function isDateAvailabele(date) {
// check your date formatting with the dates in the array
}
Upvotes: 2
Reputation: 10681
You can use like this, only available dates will select other will unselectable. check in already given example.
You can add into the array as:
var availableDates = ["9-5-2015","14-5-2015","15-5-2015"];
Fiddle - http://jsfiddle.net/yXMKC/1389/
Upvotes: 2