Step-by-step guide for sending information to a personalized API using Ajax on the Syncfusion Angular Scheduler

I'm currently grappling with how to send data to my API whenever a new event is created using the editor window. My approach so far involves using Ajax to fetch content, as seen in the code snippet below;

const ajax: Ajax = new Ajax(
  "https://localhost:3486/api/CalendarEvents?StartDate=" + startDate + "&EndDate=" + endDate,
  "GET",
  true
);
ajax.send().then();
ajax.onSuccess = (data: string): void =>
{
  this.scheduler.eventSettings = {
    dataSource: JSON.parse(data).map((value, index) => ({
      id: index,
      Subject: value.title,
      StartTime: value.startDate,
      EndTime: value.startDate
    })),
    fields: {
    }
  };
};
ajax.onFailure = (): void  =>
{

};

Additionally, I am curious about how to obtain the currently selected date range when the user modifies the date on the scheduler through view or date navigation.

onActionComplete(args: ActionEventArgs): void {
    if (args.requestType == "dateNavigate") {
      // How can the current date range be retrieved?
    }
}

[UPDATE] I have now discovered how to retrieve the presently selected date range:

onActionComplete(args: ActionEventArgs): void {
    if (args.requestType === "viewNavigate" || args.requestType === "dateNavigate") {
      const currentDates: Date[] = this.scheduleObj.getCurrentViewDates();
      const startDate = currentDates[0];
      const endDate = currentDates[currentDates.length - 1];
    }
  }

Answer №1

We have reviewed your query regarding "How to send data to a custom API using Ajax on Synfusion Angular Scheduler" and have created a sample with a service for your convenience.

app.component.ts:  
  myClickFunction(args: any): void {
    let schObj = (document.querySelector('.e-schedule') as any)
      .ej2_instances[0];
    const ajax = new Ajax('http://localhost:54738/Home/GetData', 'GET', false);
    ajax.onSuccess = (data: any) => {
      schObj.eventSettings.dataSource = JSON.parse(data);
    };
    ajax.send();
  }
  onBegin(args: any): void {
    if (args.requestType === 'eventCreate') {
      this.temp = true;
      let schObj = (document.querySelector('.e-schedule') as any)
        .ej2_instances[0];
      const ajax = new Ajax(
        'http://localhost:54738/Home/Insert',
        'POST',
        false
      );
      ajax.data = JSON.stringify(args.data[0]);
      ajax.onSuccess = (data: any) => {
        schObj.eventSettings.dataSource = JSON.parse(data);
      };
      ajax.send();
    } else if (args.requestType === 'eventChange') {
      let schObj = (document.querySelector('.e-schedule') as any)
        .ej2_instances[0];
      const ajax = new Ajax(
        'http://localhost:54738/Home/Update',
        'POST',
        false
      );
      ajax.data = JSON.stringify(args.data);
      ajax.onSuccess = (data: any) => {
        schObj.eventSettings.dataSource = JSON.parse(data);
      };
      ajax.send();
    }
  }

 

Sample: https://stackblitz.com/edit/angular-schedule-custom-adaptor?file=app.component.ts Service:

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

Building a different theme using the ng or npm command can be achieved by following these steps

In an attempt to utilize different npm commands for building distinct themes, such as running 'npm run red' (to launch index with red.html) or 'npm run blue' (to initiate index with blue.html). npm run red npm run blue I have configur ...

Accessing property values from a map in Angular

Is there a way to retrieve a property from a map and display it in a table using Angular? I keep getting [object Object] when I try to display it. Even using property.first doesn't show anything. //model export interface UserModel { room: Map ...

"Exploring the power of D3, TypeScript, and Angular 2

I am facing challenges incorporating D3 v4 with Angular 2 (Typescript). While exploring D3 v4, I have referred to several solutions on StackOverflow without success. I have imported most of the necessary D3 libraries and typings (utilizing TS 2.0) and adde ...

Validation of time input using Angular Material within a ReactiveForm

Currently immersed in Angular 17 along with Material theme, I find myself faced with a scenario involving Reactive Forms housing two time-input fields. The array [minHour, maxHour] should represent a range of Hours, let's say [09:00 , 13:00]. HTML [ ...

SignalR 2.2 application encountering communication issues with client message reception

I am facing an issue in my application where clients are not receiving messages from the Hub when a user signs in. Here is my Hub class: public class GameHub : Hub { public async Task UserLoggedIn(string userName) { aw ...

Access your Angular 5 application as a static webpage directly in your browser, no server required!

I need to run an Angular 5 application in a browser by manually opening the index.html file without the use of a server. My client does not have access to any servers and simply wants me to provide a package (dist folder) for them to double-click on the in ...

Struggling with a Nextjs Stripe issue? The expected signature for payload does not match any found signatures

Struggling to integrate data from Stripe check out events into my orders database, facing issues with finding the signature while testing the web hook. Check out route: app/api/webhooks/checkout/route.ts import Cors from "micro-cors"; import { h ...

Tips on resolving handlebars 'module not found' error in typescript while compiling to umd

In my client-side JavaScript library written in TypeScript, I am attempting to incorporate Handlebars. However, when I try to import using import * as Handlebars from 'handlebars', I encounter an error message stating that TypeScript "cannot find ...

ReactJS - Opt for useRef over useState for props substitution

Presented below is my ImageFallback component, which serves as a backup by displaying an svg image if the original one is not available. export interface ImageProps { srcImage: string; classNames?: string; fallbackImage?: FallbackImages; } const Im ...

Different ways to categorize elements of Timeline using typescript

I have some code that generates a timeline view of different stages and their corresponding steps based on an array of stages. Each stage includes its name, step, and status. My goal is to organize these stages by name and then display the steps grouped un ...

The process of importing does not produce the anticipated System.register

I'm a beginner with Angular2, currently learning and practicing by doing exercises. I am enrolled in a Udemy course and comparing my exercise progress with the instructions provided. Here is a snippet from my app.component.ts file: import {Component ...

Can the swiping feature be turned off while the image is zoomed in?

For a project, I am utilizing the angular2-useful-swiper wrapper with iDangerous Swiper. I am seeking a way to disable the swiping functionality when an image is zoomed in. After researching the Swiper Api, I have not found any information on how to achie ...

What is the best way to refresh the snapshots in my React/TypeScript project?

I am working on a React/TypeScript project that utilizes the Jest testing framework. Occasionally, after making changes to my code, Jest will compare it to the snapshots and generate an alert requesting me to update them. However, there are instances where ...

Blending TypeScript declaration files and Node.js require across various files within an internal module

Is it problematic to mix Node.js modules (require) with TypeScript definition files (d.ts) multiple times within a module? In my case, I organize my modules into namespaces per folder similar to how it's done in C#. After compiling them all using tsc ...

Angular2: Implement a feature to append textbox input to a span element upon button click

I'm completely new to Angular2 and I could really use some assistance with the following task. I need to take the input from a textbox and add it to a span in HTML. The requirement is to only make changes in the .ts file. I'm having trouble figu ...

Jest locates the test cases, yet fails to gather code coverage

Currently, I am in the process of gathering test coverage data for this specific project by utilizing: yarn test --coverage # example: "react-scripts test --coverage" The configuration settings for my Jest setup are as follows: "jest": { "collectC ...

Can an entire application built with a combination of PHP, JavaScript, and HTML be successfully converted to Angular 7?

After creating a complex application that heavily relies on JavaScript, PHP, HTML, and numerous AJAX calls, I am considering migrating the entire codebase to Angular 7. Is it feasible to achieve this transition without requiring a complete rewrite in Ang ...

Angular Routing: Dynamically loading modules as children within lazy loaded modules

I am working on a complex application where I need to load a module as a child of lazy loaded modules. For instance, I want the URL path to look like this: https://localhost:8080/ui/examplemodule/new The examplemodule and new are separate modules with t ...

Angular throws a 404 error when making a JSONP http request

I've been incorporating Mailchimp integration into an Angular application. For using it in pure JS, I retrieved the code from the embedded form on the Mailchimp site: <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js ...

Creating a TypeScript type that extracts specific properties from another type by utilizing an array of keys

In my TypeScript journey, I am working on crafting a type that can transform a tuple of keys from a given type into a new type with only those specific properties. After playing around with the code snippet below, this is what I've come up with: type ...