Upcoming Events - ListView Top X

9 posts, 0 answers
  1. Bill
    Bill avatar
    82 posts
    Member since:
    Feb 2013

    Posted 13 Dec 2017 Link to this post

    I have a request to create a widget that shows the next X upcoming events using MVC/C#. I figured the easiest way would be to create a ListView that pulls from the scheduler's datastore and take top X.

    How can we tap into the logic of the scheduler to generate events from the event definitions/rules (e.g. handle recurrence rules, recurrence exceptions, timezones, etc)? I would think we can use the data from the schedulers datastore to generate events between now and an end date and take the next X upcoming.

    If this is not possible, I assume we'd have to go down a more complex solution by using the scheduler with a custom view (like an agenda view) but I'd need to figure out how to show only the next X events and not all of them between two dates.

  2. Tyler
    Tyler avatar
    68 posts
    Member since:
    Feb 2017

    Posted 13 Dec 2017 in reply to Bill Link to this post

    How are you getting your events? From a database that you will be querying?

    If so, query the events, use the query to limit the number you get back, construct a list of kendo.SchedulerEvents based on your schema in the scheduler dataSource, and pass that to the e.success in the read of the dataSource.

    And Agenda view seems to fit your needs. If you limit the number you get back in the query, all the scheduler has to do is display it. You will need a 'custom' agenda view though. I put custom in quotes because all you have to do is change the end date most likely. Here is an example I did to make a day agenda view (only show one day at a time)

     

    var AgendaDayView = kendo.ui.AgendaView.extend({
                        endDate: function() {
                            var date = kendo.ui.AgendaView.fn.startDate.call(this);
                            return date;
                        },
                        name: 'AgendaDay'
                    });

     

    It is quite simple when you are only changing the date range.

     

    What you can do (in your query, or javascript once you get the events) is sort the events by date, then take the first X, depending on your cutoff (if you can't limit them in the query), and put them in your scheduler. Then set your custom agenda view end date to the date of the last event date in your event array (because we know that is the farthest out date since we sorted them by date).

  3. Bill
    Bill avatar
    82 posts
    Member since:
    Feb 2013

    Posted 13 Dec 2017 in reply to Tyler Link to this post

    I've tried most of the options you mentioned today. Yes, we are getting events from a DB. The problem resides with recurrence rules & exceptions. Take a daily recurrence rule, if I wanted to show the next 10 events in the custom agenda view then 1 record would return from the database but the custom agenda view would generate 30 events if an endDate +30 from today. I'd have to know somehow to set the endDate of the custom agenda view at 10 days if I wanted the next 10 events *** if that was the only event rule ***. There's no way for me to know exactly what the endDate should be and the quantity of events would still not have a hard max as the last day may have more than the desired quantity of events.

    What I am after now, is a way/event to tap into after the scheduler control has generated all the events from the event rules and before it has been rendered to the UI. If so, I could remove excess events to ensure no more than the max # of events is shown.

    I've attached a screenshot showing the scheduler widget using a custom agenda view. I'm close outside of limiting the # of events displayed.

     

  4. Tyler
    Tyler avatar
    68 posts
    Member since:
    Feb 2017

    Posted 13 Dec 2017 in reply to Bill Link to this post

    They way I interact with my database, and how it creates and handles events, is it creates and stores events given recurrence information, so if I make an event every week for the next 4 weeks, it will create 4 events that I can query (Salesforce database). So it makes it easy for me, because I don't use kendo recurrence, I work with recurrence on the Salesforce side, so I would just query my events like normal and get the results you are after. 

    But having the scheduler add however many recurrences after it adds the event to the view does make it tough...

     

    What miiiight work, is after adding your events and letting the scheduler do its thing with the recurrence rules, get the dataSource data again (which should be your list of events, that may include the recurring events it added?) and then cut that down to the first 10, then re-read that back into your dataSource and refresh.

    Now 100% sure the recurring events get added to the dataSource data, though. Would have to experiment with that.

  5. Bill
    Bill avatar
    82 posts
    Member since:
    Feb 2013

    Posted 13 Dec 2017 in reply to Tyler Link to this post

    Yeah, it adds 1 event w/ all recurrence info in it, so it is not easy to query. I've tried the scheduler ondatabinding and ondatabound to see and the item counts are what comes from the database (not exploded using recurrence info) :( 
  6. Tyler
    Tyler avatar
    68 posts
    Member since:
    Feb 2017

    Posted 14 Dec 2017 in reply to Bill Link to this post

    Another option, which should work perfectly fine with the recurring events. Is in the agenda view, in the dataBound event of the scheduler, grab all rows (<tr> elements) of the agenda view k-scheduler-table, then loop through and anything beyond your desired count, just change its display style to none.

    Here is an example where I only accept 3 events in the agenda. I start my loop at 3, and display:none everything from then on. It looks to work quite well. And you will be able to navigate the agenda view just fine and it will reveal more events for later dates as they come into the cutoff count.

  7. Tyler
    Tyler avatar
    68 posts
    Member since:
    Feb 2017

    Posted 14 Dec 2017 in reply to Tyler Link to this post

    Oh, and that example is the kendo scheduler demo. You need only concern yourself with my dataBinding event function.
  8. Bill
    Bill avatar
    82 posts
    Member since:
    Feb 2013

    Posted 14 Dec 2017 in reply to Tyler Link to this post

    Thanks Tyler. Looping the rows on databound and hiding event rows that exceed their desired display count should do the trick for this business case. While a hack - it does work.

    I'd still like to see if the Telerik Team has any feedback on generating events from the scheduler data store - server side - using C#. That way we can filter them out or use other UI controls with the data rather than being forced to use the scheduler control to view them.

  9. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    795 posts

    Posted 15 Dec 2017 Link to this post

    Hi Bill,

    The Telerik suites does not offer a C# helper / method that would allow you to expand a Kendo Recurring event into multiple occurrences. An implementation of such server-side parsing logic for the recurrence rule field is not available. Nevertheless, knowing that the Recurrence rule string follows the RFC 5545 specification, you could implement your own helper.

    Alternatively, you will have to follow the Tyler's suggestion from his previous post.

    Regards,
    Veselin Tsvetanov
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top