Numerous events have been successfully integrated into the angularjs-bootstrap-calendar

Currently, I am facing a challenge with loading all my event data from the server using angular-bootstrap-calendar. Due to the large volume of events, it is taking a considerable amount of time to load.

I am exploring the possibility of fetching only a month's worth of data based on the current view (month, week, day) without displaying the year. When switching to the next month, I would then retrieve data for that specific month.

At present, I fetch all the data during the initial calendar load, but I am unsure how to fetch data when switching views.

 var urlapievents = $location.protocol() + "://" + $location.host() + "/api/events/" ;
     $http.get(urlapievents).success(function(events) {

A possible solution:

Retrieve the year and month of the current view, send this information to the API, and fetch events only for that particular year-month:

Javascript:

 vm.viewChangeClicked = function() {

     var viewDateYearMonth = moment(vm.viewDate).format('YYYY-MM');

     var urlapieventsall = $location.protocol() + "://" + $location.host() + "/api/events/" + viewDateYearMonth  ;

     $http.get(urlapieventsall).success(function(events) {
        vm.events = events.events; 
     });
};

HTML:

<div class="col-md-6 text-center">
  <div class="btn-group">
    <label class="btn btn-primary" ng-model="vm.calendarView" uib-btn-radio="'month'" ng-click="vm.cellIsOpen = false; vm.viewChangeClicked()">Month</label>
    <label class="btn btn-primary" ng-model="vm.calendarView" uib-btn-radio="'week'" ng-click="vm.cellIsOpen = false; vm.viewChangeClicked()">Week</label>
    <label class="btn btn-primary" ng-model="vm.calendarView" uib-btn-radio="'day'" ng-click="vm.cellIsOpen = false; vm.viewChangeClicked()">Day</label>
  </div>
</div>

I have also implemented logic to compare previous yyyy-mm with current yyyy-mm to avoid unnecessary API calls.

Answer №1

When retrieving your events in json format, you have the option to utilize startParam and endParam for additional customization. Implement them like so:

$('#calendar').fullCalendar({
  events: function(start, end, timezone, callback) {
    if (request) {
      request.abort();
    };
    $.mobile.loading('show');
    request = $.ajax({
      type: "POST",
      url: "../Services/Calendar/CalendarService.asmx/GetEvents",
      cache: false,
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      data: "{ dtStart: " + JSON.stringify(start) + ", dtEnd: " + JSON.stringify(end) + "}",
      success: function(data) {
        var events1 = [];
        $(data.d).each(function() {
          events1.push({
            title: this.Title,
            start: this.Start,
            end: this.End,
            id: this.Id
          });
        });
        callback(events1);
        $.mobile.loading('hide');
      },
      error: function(jqXHR, textStatus, errorThrown) {
        if (jqXHR.statusText == 'abort') {
          $.mobile.loading('hide');
          return;
        } else {
          alert('There was an error');
          $.mobile.loading('hide');
        }
      }
    });
  }
});

To learn more about these parameters, refer to: https://fullcalendar.io/docs/event_data/events_json_feed/

Answer №2

The concept you are referring to is similar to date pagination. Although this feature is not included by default (which is unfortunate because it seems quite useful), you can create your own version with a bit of effort.

To begin, the datepicker stores a JS Date object within the ng-model. You can use $watch to track changes and extract the current year/month/day from it.

$scope.modelDate = new Date()
...
$scope.$watch('modelDate', function(newDate, oldDate) {
    newDate.getDay(); // 5
    newDate.getMonth(); // 11
    newDate.getYear(); // 116
})

Once you have this information, you can query your database to retrieve all events for the selected month.

You can also make use of the datepicker's mode property, which indicates whether you are viewing the datepicker in day/month/year mode and can be configured within the options object.

datepickerMode C (Default: day) - Current mode of the datepicker (day|month|year). Can be used to initialize the datepicker in a specific mode.

By utilizing this property, you can fetch events for a specific month, year, or range of years.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring the Evolution of URL Routing in AngularJS

Our current website has a routing setup at site.com/products/:id, with an example URL being site.com/products/104. However, we want to remove the ID from the URL and instead display the actual product name. This means changing it to site.com/products/produ ...

skip every nth element in the array based on the specified value

The Challenge I'm currently working on a graph that relies on an array of data points to construct itself. One major issue I've encountered is the need for the graph to be resizable, which leads to the necessity of removing certain data points ...

Trouble with second function invocation in JavaScript

After creating two sets of arrays and passing them into different functions, I noticed some strange behavior. The first time I called the functions for scores1, everything worked perfectly. Likewise, the second time I called the first function (for Scores2 ...

Avoiding a browser becoming frozen during an AJAX call

I'm currently working on sending a request when a user closes the page using the onbeforeunload event. This event triggers when the tab is closed or the page is refreshed. Here's my event implementation: window.onbeforeunload = function() { ...

Distinguishing between web development, frontend, and backend: Identifying ownership of an entity by a user

In my web application, I have a setup where each user can have multiple projects and each project can have multiple users. This relationship is managed through three tables in the database: user, project, and user2project which maps the n:m relation betwee ...

Only authenticated users are permitted to write to Firebase databases

Currently, I am in the process of setting up a new Vue JS project for a blog with Firebase integration. The main objective is to allow any logged-in user to create blog posts that are saved in the Firebase real-time database at https://xxx.firebaseio.com/b ...

Visual Studio Code unable to locate source maps for typescript debugging

Looking for some help debugging a basic Hello World TypeScript file. Whenever I try to set a breakpoint, it seems like VS Code is having trouble locating the source map, even though it's saved in the same directory. I'm using Chrome as my browser ...

Implement a formatter function to manipulate the JSON data retrieved from a REST API within the BootstrapVue framework

My bootstrap-vue vue.js v2.6 app is receiving JSON data from a REST API. The data structure looks like this: { "fields": [ { "key": "name", "label": "name", & ...

Reading a JSON file using Javascript (JQuery)

Struggling to figure out how to handle a JSON file using JavaScript. Here are the details : { "streetCity": { "132":"Abergement-Clemenciat", "133":"Abergement-de-Varey", "134":"Amareins" } } I am attempting to access ...

Adjust the size of the Threejs canvas to fit the container dimensions

Is there a way to determine the canvas size based on its container in order to prevent scrolling? Setting the size based on the window results in the canvas being too large. ...

What steps can I take to resolve my password validation rule when confirming during sign-up?

Utilizing react-hook-form in combination with Material-UI for my sign-up form has been a challenge. I am currently working on implementing a second password field to confirm and validate that the user accurately entered their password in the initial field, ...

What other options are available for achieving the same functionality as FormData.delete() given its low level of support?

When building my website, I utilized the FormData.delete() method to exclude specific form fields before sending data to the server. However, I encountered a setback as this method is not supported on various browsers, including Safari. Therefore, I am in ...

Error occurred due to an improperly formatted authorization header while attempting to upload an object to S3 using the JavaScript SDK

When attempting to upload an object to Amazon S3 using their JavaScript SDK, I encounter the following error message: <Error> <Code>AuthorizationHeaderMalformed</Code> <Message>The authorization header is malformed; the reg ...

JavaScript: Trouble with statement execution

My code is designed to classify a point as 1 if it's above the line y=x, and -1 if it's below the line y=x. I visually represent this line in a canvas by plotting y=x (although due to invertion on the y-axis, it appears like y=-x). For each point ...

Is there a way for me to view the names of the images I am uploading on the console?

Recently, I've started using express and NodeJs. I've created a function called upload that is responsible for uploading images. Here is the code: const fs = require("fs"); var UserId = 2; var storage = multer.diskStorage({ destination: functi ...

What is the best method to update the content of one div with content from another page using AJAX?

Having trouble achieving smoother page loads? My goal is to utilize AJAX to specifically fetch a certain div from another page and then swap out the content of a div on this current page with the response. Below is my JavaScript script that uses AJAX to r ...

Using Angular and Typescript to implement a switch case based on specific values

I am attempting to create a switch statement with two values. switch ({'a': val_a,'b': val_b}){ case ({'x','y'}): "some code here" break; } However, this approach is not functioning as expected. ...

When text with delimiters is pasted into a Vuetify combobox, why aren't the chips separated correctly by the delimiters?

I'm attempting to create a Vuetify combobox with chips that automatically split the input based on predefined delimiters, such as ,. This means that if I paste the text a,b,c, the component should convert them into three separate chips: a, b, and c. H ...

Angular view fails to update after form submission when using ngDialog to change the scope

After starting my Angular journey, I decided to challenge myself by creating a comprehensive todo app for educational purposes. I seem to be missing something pretty basic, although I can't quite put my finger on it. It seems like there might be an is ...

Javascript - issue with accurately retrieving element offset value while scrolling

My goal is to dynamically change classes for elements based on their position during scrolling. I am trying to calculate the top offset element value and adjust the classes accordingly. Here is the function I am using: handleScroll () { const header = ...