twinssbc / Ionic2-Calendar

A calendar component based on Ionic framework
https://ionic-calendar-demo.stackblitz.io
MIT License
388 stars 197 forks source link

Month Navigation #79

Closed darrellc closed 6 years ago

darrellc commented 7 years ago

I would like to navigate months using arrow navigation buttons. How would I do interface with the calendar monthview to slide the month.

twinssbc commented 7 years ago

@darrellc You can change currentDate to the date in previous/next month.

darrellc commented 7 years ago

I did change the current date, but no refresh of the calendar.

changeMonth(direction){ console.log(this.calendar); switch(direction){ case "back": this.calendar.currentDate.setMonth(this.currentMonth - 1); break; case "forward": this.calendar.currentDate.setMonth(this.currentMonth + 1); break; } console.log(this.calendar["currentDate"]); return this.calendar; }

twinssbc commented 7 years ago

@darrellc You need to assign it back to the currentDate variable.

this.calendar.currentDate = new Date(this.calendar.currentDate.setMonth(this.currentMonth - 1));
thecodeguru360 commented 7 years ago

Actually i want to change the date using navigation buttons. 'this.calendar.currentDate' is not updating only if i change the calendar view. is there any way to swipe left and right using navigation buttons?

twinssbc commented 7 years ago

@rosehashmi It should work. Could you provide your code in your navigation button callback? Basically you just need to set the currentDate in your callback. The calendar will navigate to the corresponding month. It's also possible that you are assigning the currentDate to different object? Not the object bound to the calendar.

newbie-ionic commented 7 years ago

Hi @twinssbc, I am very new to Ionic. I am trying to show week view. But I want navigation for month also. How could I achieve that? Can you please provide me code so it will be very helpful for me. I am developing app into Ionic 3.

twinssbc commented 7 years ago

@newbie-ionic You want to navigate by month in the weekview? I suppose you will have some button to let you select the month. Then in the click callback method, you just need to set the currentDate to a date in the selected month.

newbie-ionic commented 7 years ago

Hi @twinssbc, Thank you for replying. I have written one click event on previous button to which I have set previous month date. But calendar view is not rendering as per changed month. It is showing same week view.

twinssbc commented 7 years ago

@newbie-ionic Could you provide your code that is changing the date in the click callback method?

newbie-ionic commented 7 years ago

I have taken one button for previous month view. By default I want week view. So I have changes mode = "week".

previousMonthButton() { this.calendar.currentDate = new Date(this.calendar.currentDate.setMonth(this.myDate.getMonth() - 1)); }

twinssbc commented 7 years ago

@newbie-ionic I just tested that it's working. Is it possible something wrong with this.myDate?

newbie-ionic commented 7 years ago

Can you please tell me what is wrong with code? It will be really helpful for me. Your help will be appreciated.

newbie-ionic commented 7 years ago

I have declared myDate = new Date(); I am able to get previous month title which is bind to {{viewTitle}}. But when I click on previous month, I am able to see days from 1 to 7 of previous month. Other days are not displaying. It will show next month's days directly.

twinssbc commented 7 years ago

The problem is myDate never changes? Below code is working in my project

this.calendar.currentDate = new Date(this.calendar.currentDate.setMonth(this.calendar.currentDate.getMonth() - 1));
newbie-ionic commented 7 years ago

Thank you @twinssbc.

chethangowda commented 7 years ago

@twinssbc I want to refresh the calendar onSwipe left and right, which method will get hit on swipe Help me out here...

twinssbc commented 7 years ago

@chethangowda onRangeChanged will be triggered if you set the queryMode to 'remote'.

NIYASSURABHI commented 4 years ago

What will happens if i click navigation button from 31 January to February? it is coming to march 2. How can handle this?