-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Custom Date Ranges in the Template #72
Comments
This would be a terrific feature. |
Then maybe it should also be possible to configure the length of increments. I have a use case in which I display two calendars (so length: 2 months) but the next button increments only of 1 month. So you start with |
@puccio absolutely yes! Here's an updated API draft. $().clndr({
template: $('#template').html(),
lengthOfTime: {
days: 14,
incrementBy: 7
}
}); In reviewing the codebase, this all is possible but will require a pretty insane amount of refactoring... The idea of a month is hardcoded in a lot of ways. I think it's absolutely worth it though. |
Hey there! Any progress on this feature (I can't wait for it :-))? |
@palodelincak ha! Glad you're excited. I've been planning it in my spare time and thought I might be able to start developing on Sunday, however it is going to take some time since it is a big refactor. (Are you interested in contributing?) Also, gotta admit, I'm putting most of my energy into a new project I'll be releasing soon, so that is definitely competing for my attention! |
@kylestetz I was trying to hack it myself, but I gave up - it's too big for me. Glad to hear you're going to work on it! I'm sorry, but can you be more specific with release date, please (I know it's probably not possible)? It'll be done in one week, one month, one year? :-) I need this info very badly. |
I can guarantee you it will be done by March 1st. Wish I could promise you something sooner but that's pretty realistic. |
March 1st will be awesome. Thanks! |
Hi there! Firstly I want to say thanks for all your work on this, it's a great idea for a plugin and I love being able to use templates. I was wondering if as part of the custom date ranges feature you're discussing here, if it'd be possible to create a year view. Something like...
And then in the template you could have a nested loop to go through months and days. So that would give an entire year view of 2014. What do you think? |
Yep, that example would work perfectly. You could also use I'm setting it up so that if you specify months = [
{
month: moment(), // the month as a moment object
days: Array // same as the days array you are used to in clndr
}
] Which will be really easy to loop over. |
Brilliant, thanks so much! Really looking forward to this 👍 |
Hey guys Good news: I think we're all set with this new feature. It was sort of tricky and I'm not aesthetically pleased with the resulting code, but it works! I just pushed a branch I've been working from... Before I merge it, would any of you guys mind giving it a test run? I'm not 100% sure I've covered every edge case so it'd be awesome if you guys could mess around with it. https://github.com/kylestetz/CLNDR/tree/intervals I haven't written docs for it yet, however if you look at /example/test.js and /example/test.html the last two examples are a three-month and a two-week calendar. The final API I settled on is: lengthOfTime: {
days: #, // length of calendar in days
months: #, // length of calendar in months
interval: #, // amount to move the calendar by for each next/previous click
startDate: String or moment() // the date to use as a starting point...
// by default it's the current month using the `month` option,
// and it's the first weekday before today using the `days` option (e.g. Sunday)
} Using the months: [
{
month: moment(), // a moment object set to the start of this particular month
days: Array // the regular clndr days array
}
] You'll have to write a custom template to take advantage of this stuff. Let me know if you guys have any questions! P.S. Thanks for your support & enthusiasm- you guys make this a fun project to work on. |
Hey Kyle, thanks for this! I'm stuck working on another project at the moment but will have a play with this tonight and see if I can get it running. Looking forward to it, thanks again! |
I'll play around with the new branch this week. |
Hey Kyle, Ok so I've had a play around with the branch, seems to be working which is great, thanks! There's a couple of things I have questions on which may be either something I'm just missing, or useful improvements. To give some context, I'm building a year planner as part of an app, that displays the events for the currently selected year. So first question, is there, or do you think there's a reasonable use case for an option that will output a full 31 days for each month to allow for a grid-like layout (with an appropriate day.classes hook for styling purposes). I currently have the below screengrab: Secondly, and apologies as I realise this is unrelated, but is there a destroy method? I'm currently displaying only one year, and when the year is changed from elsewhere in the app I need to hit the API and re-render the clndr. Thanks for your help! Let me know if you have a paypal, I'd like to buy you a beer / coffee! |
answer to first question: are you just trying to fill in those extra boxes at the end? You could check the length of each month in your template, find the remainder (31 - month[].days.length) and do a lil while loop to generate some empty boxes... This is something best solved in the template. answer to second question: I found a bug! Which I fixed, please grab the updated version. There is an API for programmatically controlling the calendar. When making your clndr instance, save it to a variable: var myCalendar = $('#calendar').clndr(); and you can call: myCalendar.nextYear()
myCalendar.previousYear()
myCalendar.setYear(2015)
// etc... The README has some more docs on these. You are welcome! Will you perchance be attending JSFest in SF next month? I will be there, drinking the beers. |
Thanks for getting back to me. First question, yep, just fill the extra boxes... Sounds sane to just write something in the template for that. Had to tweak it slightly as the days.length array also contains stuff from the neighbouring months:
Second question, ahh brilliant, I'll just pass in a new events array and switch the year then which will solve the problem. Unfortunately I'm based in London so probably won't be making it to SanFran, sounds good though! |
Wow! Thanks for this! I was able to create one day, two weeks and one month view based on my requirements - so your improvement is simply the best! I would love to have .destroy() (as @MerlinBB) method. And why? I'm going to allow users to change calendar views between one day => two weeks... So I must destroy one instance and initialise other instance. Right know I'm just killing plugin data and removing template children, but some callbacks are still working... Or instead of destroy() method would be nice to have ability to re-render it with new options. |
@palodelincak you could probably maintain two separate calendar instances and just hide the one you aren't using... They can share callbacks and events if necessary. HOWEVER I tried to write this thing with the ability to change You can change the clndr.options.lengthOfTime.days = 14; Now it's set up to view two weeks, but we have to trigger a render. We can't just call clndr.setIntervalStart(clndr.intervalStart.weekday(0)); (as of this update clndr maintains two variables called To switch back to a one day view: clndr.options.lengthOfTime.days = 1;
clndr.setIntervalStart(/* whichever day you want to switch to, as a moment object */); So the last piece of this is that you probably have two different templates for the day and the weeks view. That's where we can use $('#calendar').clndr({
template: $(),
lengthOfTime: {
days: 14,
interval: 7
},
extras: {
dayView: false
}
}); Now in your template you can access clndr.options.lengthOfTime.days = 1;
clndr.options.extras.dayView = true;
clndr.setIntervalStart(/* whichever day you want to switch to, as a moment object */); ...and now your template can be set up like this: <% if(extras.dayView){ %>
<markup for the single day view />
<% } else { %>
<markup for the week view />
<% } %> Let me know how that works for you! |
Works like a charm. Many thanks! This plugin is limitless 👍 I think this one is a bug - variable Is there some way of getting whole date range in month including days in adjacent months? For example - first row in February begins with 27th January and last row ends with 9th March. I would like to load events for adjacent days - from 27th Jan to 9th March and not just for 1st Feb - 28th Feb. I was looking at source code but filling blank (adjacent) boxes is hardcoded to days array and this array is not available in clndr callbacks. PS: I'm not kidding, but this is the best 3rd party plugin I have ever worked with! |
Thanks for catching that bug, just patched it up. Adjacent days are controlled by the Is this not what you are seeing? All the tests for adjacent months are passing at the moment. Perhaps tell me a little bit more about the setup and what you're seeing that seems broken. P.S. thanks :) |
Hi, any news on this? I see the 'intervals' branch is kind of old. Is this already implemented in the master branch? |
Hey- no news unfortunately. I've been busy and have prioritized other projects over this update, partly because I'd rather refactor the entire codebase to 2.0 than add features to this version. Due to the relatively few people who were looking for this feature, I didn't see it as a huge priority. I ran into some issues given that clndr was originally written with months in mind and this was intended to replace months with intervals. (My ideal situation with clndr would be to find some equally-motivated collaborators who would be willing to hash out and write 2.0 from scratch in a modular, testable fashion that can live and grow for a long time!) I'll have some time next month when I can definitely take some action on this branch. Thanks for checking in! |
Hi kylestetz
hope you will guide me. |
Just realized I can close this! This feature was added in v1.2.11 thanks to the hard work of @mikegioia. |
@palodelincak brought up the point in issue #71 that creating a view in increments other than one-month-at-a-time is difficult, bordering on unreasonable.
I am going to move forward implementing an option that allows you to choose an arbitrary length of days to have available in the template. Here's what it could look like:
Specifying
length.days
here tells clndr "I want you to give me 7 days at a time in my template". Thus theclndr-next-button
will increment the data by 7 days instead of a month. I'm thinking there will be a different set of callbacks specific to this situation, perhapsonNextIncrement
andonPreviousIncrement
.Specifying a concrete number of days doesn't work well if you want to show several months at a time, so:
This would behave almost exactly like clndr does now, except that you would get three months in your template instead of one. Perhaps there are some template functions that would make sorting the days out into months a little easier.
Feedback is welcome as always- I'm pretty sure @sylouuu will have something to say about this!
The text was updated successfully, but these errors were encountered: