Closed skizzy closed 7 years ago
The only thing I saw that was wrong is the part on the 'n' (I suppose that means "Month") is not on 0 based;
Now about the weird showing dates I know nothin of Python/Django but what I understand is that you're fetching the data with {{mydate.checkin_booked_date|date:"Y, n, j" }}
and you're givin the formar "Year, Month, Day"
Can you please try to set datasource this way and print the array too, to check out if it's JS new Date who's doing things wrong:
` var myData = [];
for (var i = 0; i < Identificacion.length; i++) { //{% for mydate in get_all_date %}
myData.push({
id: Identificacion[i],
name: Name[i],
startDate: new Date( parseInt(AñoIn[i]), parseInt(MesIn[i]-1), (DiaIn[i]), parseInt(HorasIn[i]), parseInt(MinutosIn[i])), //StartDate[i],
endDate: new Date( parseInt(AñoFin[i]), parseInt(MesFin[i])-1, (DiaFin[i]), parseInt(HorasFin[i]), parseInt(MinutosFin[i])),//EndDate[i],
location: Location[i]
});
};
var dataSource = $('#calendar').data('calendar').getDataSource();
dataSource = myData;
$('#calendar').data('calendar').setDataSource(dataSource);`
The n is in month. You can get the idea here. https://docs.djangoproject.com/en/1.10/ref/templates/builtins/#date
For the js code you wrote, what function should I change in the template? I don't know js that much.
In the template take out the option
dataSource: [ {% for mydate in get_all_date %} { id: {{ forloop.counter0 }}, name: '{{mydate.hotelrooms.room_name }}', location: '{{mydate.booked_by }}', startDate: new Date({{mydate.checkin_booked_date|date:"Y, n, j" }}), endDate: new Date({{mydate.checkout_booked_date|date:"Y, n, j" }}) }, {% endfor %} ]
Change it with
$('#calendar').calendar({"options here"});
var Year;
var Month;
var Month;
var myData = []; {% for mydate in get_all_date %} Year= {{mydate.checkin_booked_date|date:"Y" }}; Month= {{mydate.checkin_booked_date|date:"n" }} - 1; to get the month starting with 0 Day= {{mydate.checkin_booked_date|date:"j" }} - 1; myData.push({ id: {{ forloop.counter0 }}, name: {{mydate.hotelrooms.room_name }}, startDate: new Date( parseInt(Year), parseInt(Month), parseInt(Day) ) , endDate: new Date( parseInt(Year), parseInt(Month), parseInt(Day + 3) ) , //Added 3 days just as test case location: '{{mydate.booked_by }}' }); };
And then load the DataSource with this var dataSource = $('#calendar').data('calendar').getDataSource();
dataSource = myData; $('#calendar').data('calendar').setDataSource(dataSource);`
BTW You should try with the simple options first something like mine on the attached image
When I insert the dates in the docs, I works fine. I understand that js starts from 0 with months. I expect the calendar to display on April 10-19, 2017. But showing on July 1-14, 2016 is what baffles me. I'd been it shows that way, I would have adjust it to make it read based on javascript 0 months reading.
Now after posting your code, the calendar didn't show up.
<script type="text/javascript" class="publish">
$(function() {
$('#calendar').calendar();
var Year;
var Month;
var Day;
var myData = [];
{% for mydate in get_all_date %}
Year= {{mydate.checkin_booked_date|date:"Y" }};
Month= {{mydate.checkin_booked_date|date:"n" }} - 1;
//to get the month starting with 0
Day= {{mydate.checkin_booked_date|date:"j" }} - 1; myData.push({ id: {{ forloop.counter0 }}, name: {{mydate.hotelrooms.room_name }}, startDate: new Date( parseInt(Year), parseInt(Month), parseInt(Day) ) , endDate: new Date( parseInt(Year), parseInt(Month), parseInt(Day + 3) ),
//Added 3 days just as test case
location: '{{mydate.booked_by }}'
{% endfor %}
});
var dataSource = $('#calendar').data('calendar').getDataSource();
$('#calendar').data('calendar').setDataSource(dataSource);
});
I replaced my the whole of my code with yours. Kindly check the code I posted if I miss anything or parenthesis or semi-colon.
There's a extra ' }); ' after {% endfor %} ; Now with this same set up, but data fetched from MSSQL and ASP, is working for me can you run the code and show console message on the web browser to see if is there any weird error and print myData with console.log(myData ) to see what is actually fetching the array should be something like this (Firefox)
Not still showing the calendar, look at the source code below.
<script type="text/javascript" class="publish">
$(function() {
$('#calendar').calendar();
var Year;
var Month;
var Day;
var myData = [];
Year= 2016;
Month= 6 - 1;
//to get the month starting with 0
Day= 1 - 1; myData.push({ id: 0, name: Mongo FC Suites, startDate: new Date( parseInt(Year), parseInt(Month), parseInt(Day) ) , endDate: new Date( parseInt(Year), parseInt(Month), parseInt(Day + 3) ), //Added 3 days just as test case
location: 'Dave Mason'
});
});
var dataSource = $('#calendar').data('calendar').getDataSource();
$('#calendar').data('calendar').setDataSource(dataSource);
});
</script>
Thanks for the support William! So sorry for disturbing you. I've fixed it. I was getting dates from the booked DB table instead of the Calendar DB table. I was tired last night!
Thanks again man. You rock.
I really like this Calender. Kudos to the developers behind it.
I want to use this calendar for a booking site. The calendar will show booked dates by user and name of the room booked. I built my webapp with Python/Django. After following the 'full example' in the docs, the data I have in my database is different from the ones on the calendar.
In my database, I have these dates:
For a Hotel with Room 1 named Love Room
Check-in : 2017, 03, 10 Check-out: 2017, 03, 19
But it's showing me the below dates in the calendar
startDate: new Date(2016, 6, 1), endDate: new Date(2016, 6, 14)
For another Hotel with Room 1 named Mingle Room
Check-in : 2017, 06, 15 Check-out: 2017, 06, 18
But it's showing me the below dates in the calendar
startDate: new Date(2016, 6, 4), endDate: new Date(2016, 6, 16)
startDate: new Date(2016, 12, 19), endDate: new Date(2016, 12, 22)
CODE
Is it a bug with the calendar? or how do I go aboutshowing the right date in calendar from database?