<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Bryntum - Medium]]></title>
        <description><![CDATA[Bryntum creates advanced Gantt project management UI components for web application development, as well as developer tools for testing and error monitoring. - Medium]]></description>
        <link>https://medium.com/bryntum?source=rss----32ca805267d8---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Bryntum - Medium</title>
            <link>https://medium.com/bryntum?source=rss----32ca805267d8---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 17:07:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/bryntum" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to connect and sync Bryntum Calendar to a Microsoft Outlook Calendar]]></title>
            <link>https://medium.com/bryntum/how-to-connect-and-sync-bryntum-calendar-to-a-microsoft-outlook-calendar-67da24a10241?source=rss----32ca805267d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/67da24a10241</guid>
            <category><![CDATA[outlook-calendar]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[microsoft-outlook]]></category>
            <category><![CDATA[bryntum]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ritza]]></dc:creator>
            <pubDate>Wed, 07 Jun 2023 18:33:08 GMT</pubDate>
            <atom:updated>2023-06-08T07:31:37.821Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*99Tc6ebOZeJblcahMprQzg.png" /></figure><p><a href="https://www.bryntum.com/products/calendar/">Bryntum Calendar</a> is a fully customizable, responsive, high-performance JavaScript component that’s built using ES6+ and Sass. It can easily be integrated with React, Vue, or Angular. In this tutorial, we’ll connect and sync the Bryntum Calendar to a Microsoft Outlook Calendar. We’ll do the following:</p><ul><li>Create a JavaScript app that a user can log in to using their Microsoft 365 Developer Program account.</li><li>Use Microsoft Graph to get the user’s Microsoft Outlook Calendar events</li><li>Display the Microsoft Outlook Calendar events in a Bryntum Calendar.</li><li>Sync event changes in the Bryntum Calendar with the user’s Microsoft Outlook Calendar.</li></ul><p>Once you’ve followed this guide, you’ll be able to sync your Bryntum and Outlook calendars, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I02lSZTS0DWBAdAOTqB8GA.gif" /></figure><h3>Getting started</h3><p>Clone the <a href="https://github.com/ritza-co/bryntum-outlook-calendar-app-starter">starter GitHub repository</a>. The starter repository uses <a href="https://vitejs.dev/">Vite</a>, which is a development server and JavaScript bundler. You’ll need Node.js version 14.18+ for Vite to work.</p><p>Now install the Vite dev dependency by running the following command:</p><pre>npm install</pre><p>Run the local dev server using npm run dev and you’ll see a blank page. The dev server is configured to run on http://localhost:8080/ in the vite.config.js file. This will be needed for Microsoft 365 authentication later.</p><p>Let’s create our Bryntum Calendar now.</p><h3>Creating a calendar using Bryntum</h3><p>We’ll install the Bryntum Calendar component using npm. Follow the guide to installing the Bryntum Calendar component <a href="https://www.bryntum.com/docs/calendar/guide/Calendar/quick-start/javascript-npm">here</a>.</p><p>The style.css file contains some basic styling for the calendar. We set the &lt;HTML&gt; and &lt;body&gt; elements to have a height of 100vh so that the Bryntum Calendar will take up the full height of the screen.</p><p>Let’s import the Bryntum Calendar component and give it some basic configuration. In the main.js file add the following lines:</p><pre>import { Calendar } from &quot;@bryntum/calendar&quot;;<br>import &quot;@bryntum/calendar/calendar.stockholm.css&quot;;<br><br>const startDate = new Date();<br>const endDate = new Date();<br>endDate.setHours(endDate.getHours() + 1);<br>const startDateStr = startDate.toISOString().substring(0, 19);<br>const endDateStr = endDate.toISOString().substring(0, 19);<br><br>const calendar = new Calendar({<br>  appendTo: &quot;calendar&quot;,<br><br>  resources: [<br>    {<br>      id: 1,<br>      name: &quot;Default Calendar&quot;,<br>      eventColor: &quot;green&quot;,<br>    },<br>  ],<br>  events: [<br>    {<br>      id: 1,<br>      name: &quot;Meeting&quot;,<br>      startDate: startDateStr,<br>      endDate: endDateStr,<br>      resourceId: 1,<br>    },<br>  ],<br>});</pre><p>We imported the Bryntum Calendar and the CSS for the Stockholm theme, which is one of five available themes. You can also create custom themes. You can read more about styling the calendar <a href="https://bryntum.com/docs/calendar/guide/Calendar/customization/styling">here</a>. We created a new Bryntum Calendar instance and passed a configuration object into it. We added the calendar to the DOM as a child of the &lt;div&gt; element with an id of &quot;calendar&quot;.</p><p>We passed in data inline to populate the Calendar Resources and events stores for simplicity. You can learn more about working with data in the <a href="https://www.bryntum.com/docs/calendar/guide/Calendar/data/project_data">Bryntum docs</a>. We have a single resource, the &quot;Default Calendar&quot;. Within the calendar, there&#39;s one example &quot;Meeting&quot; event. If you run your dev server now, you&#39;ll see the event in the Bryntum Calendar:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0mbBZovqjS22A0Fi8vaQPA.png" /></figure><p>Now let’s learn how to retrieve a list of calendar events from a user’s Microsoft Outlook Calendar using Microsoft Graph.</p><h3>Getting access to Microsoft Graph</h3><p>We’re going to register a Microsoft 365 application by creating an application registration in <a href="https://azure.microsoft.com/en-us/products/active-directory/">Azure Active Directory</a> (Azure AD), which is an authentication service. We’ll do this so that a user can sign in to our app using their Microsoft 365 account. This will allow our app access to the data the user gives the app permission to access. A user will sign in using OAuth, which will send an access token to our app that will be stored in session storage. We’ll then use the token to make authorized requests for Microsoft 365 Outlook Calendar data using Microsoft Graph. Microsoft Graph is a single endpoint REST API that enables you to access data from Microsoft 365 applications.</p><p>To use Microsoft Graph you’ll need a <a href="https://account.microsoft.com/account?lang=en-hk">Microsoft account</a> and you’ll need to join the <a href="https://developer.microsoft.com/en-us/microsoft-365/dev-program">Microsoft 365 Developer Program</a> with that Microsoft account. When joining the Microsoft 365 Developer Program, you’ll be asked what areas of Microsoft 365 development you’re interested in, select the Microsoft Graph option. Choose the closest data center region, create your admin username and password, then click “Continue”. Next, select “Instant Sandbox” and click “Next”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EcpHgjN_81Sw3St2vbxuSA.png" /></figure><p>Now that you have successfully joined the developer program, you can get your administrator’s email address in the dashboard window. We’ll use it to create an application with Microsoft Azure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bXVOYC0wFGTAW0GWAJbzcQ.png" /></figure><h3>Creating an Azure AD app to connect to Microsoft 365</h3><p>Let’s register a Microsoft 365 application by creating an application registration in the <a href="https://aad.portal.azure.com/">Azure Active Directory admin portal</a>. Sign in using the admin email address from your Microsoft 365 Developer Program account. Now follow these steps to create an Azure Active Directory application:</p><ol><li>In the menu, select “Azure Active Directory”.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1SnY-2wIPcJqEu60IkrnrQ.png" /></figure><p>2. Select “App registrations”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H0OYjPrszlcs0eaUo0-Dmg.png" /></figure><p>3. Click “New registration” to create a new app registration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MlDwhEhqTFNEFtIAFGMp0A.png" /></figure><p>4. Give your app a name, select the “Single tenant” option, select “Single page application” for the redirect URI, and enter <a href="http://localhost:8080/">http://localhost:8080</a> for the redirect URL. Then click the “Register” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EpOwE1JcmXnig8XeekvYpw.png" /></figure><p>After registering your application, take note of the Application (client) ID and the Directory (tenant) ID, you’ll need these to set up authentication for your web app later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VzRGL4FEwKADFZ6f32Zz-w.png" /></figure><p>Now we can create a JavaScript web app that can get user data using the Microsoft Graph API. The next step is to set up authentication within our web app.</p><h3>Setting up Microsoft 365 authentication in the JavaScript app</h3><p>To get data using the Microsoft Graph REST API, our app needs to prove that we’re the owners of the app that we just created in Azure AD. Your application will get an access token from Azure AD and include it in each request to Microsoft Graph. After this is set up, users will be able to sign in to your app using their Microsoft 365 account. This means that you won’t have to implement authentication in your app or maintain users’ credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8TfLqaxwHHQoOb3WuKrzIQ.png" /></figure><p>First we’ll create the variables and functions we need for authentication and retrieving calendar events from Microsoft Outlook Calendar. Then we’ll add the Microsoft Authentication Library and Microsoft Graph SDK, which we’ll need for authentication and using Microsoft Graph.</p><p>Create a file called auth.js in your project’s root directory and add the following code:</p><pre>const msalConfig = {<br>  auth: {<br>    clientId: &quot;&lt;your-client-ID-here&gt;&quot;,<br>    // comment out if you use a multi-tenant AAD app<br>    authority: &quot;https://login.microsoftonline.com/&lt;your-directory-ID-here&gt;&quot;,<br>    redirectUri: &quot;http://localhost:8080&quot;,<br>  },<br>};</pre><p>In the msalConfig variable, replace the value for clientID with the client ID that came with your Azure AD application and replace the authority value with your directory ID.</p><p>The following code will check permissions, create a Microsoft Authentication Library client, log a user in, and get the authentication token. Add it to the bottom of the file.</p><pre>const msalRequest = { scopes: [] };<br>function ensureScope(scope) {<br>  if (<br>    !msalRequest.scopes.some(s =&gt; s.toLowerCase() === scope.toLowerCase())<br>  ) {<br>    msalRequest.scopes.push(scope);<br>  }<br>}<br><br>// Initialize MSAL client<br>const msalClient = new msal.PublicClientApplication(msalConfig);<br><br>// Log the user in<br>async function signIn() {<br>  const authResult = await msalClient.loginPopup(msalRequest);<br>  sessionStorage.setItem(&quot;msalAccount&quot;, authResult.account.username);<br>}<br><br>async function getToken() {<br>  let account = sessionStorage.getItem(&quot;msalAccount&quot;);<br>  if (!account) {<br>    throw new Error(<br>      &quot;User info cleared from session. Please sign out and sign in again.&quot;<br>    );<br>  }<br>  try {<br>    // First, attempt to get the token silently<br>    const silentRequest = {<br>      scopes: msalRequest.scopes,<br>      account: msalClient.getAccountByUsername(account),<br>    };<br><br>    const silentResult = await msalClient.acquireTokenSilent(silentRequest);<br>    return silentResult.accessToken;<br>  } catch (silentError) {<br>    // If silent requests fails with InteractionRequiredAuthError,<br>    // attempt to get the token interactively<br>    if (silentError instanceof msal.InteractionRequiredAuthError) {<br>      const interactiveResult = await msalClient.acquireTokenPopup(msalRequest);<br>      return interactiveResult.accessToken;<br>    } else {<br>      throw silentError;<br>    }<br>  }<br>}</pre><p>The msalRequest variable stores the current Microsoft Authentication Library request. It initially contains an empty array of scopes. The list of permissions granted to your app is part of the access token. These are the scopes of the <a href="https://oauth.net/">OAuth</a> standard. When your app requests an access token from the Azure Active Directory, it needs to include a list of scopes. Each operation in Microsoft Graph has its own list of scopes. The list of the permissions required for each operation is available in the <a href="https://learn.microsoft.com/en-us/graph/permissions-reference">Microsoft Graph permissions reference</a>.</p><h3>Using Microsoft Graph to access a user’s Outlook Calendar events for the next seven days</h3><p>Create a file called graph.js in the project’s root directory and add the following code:</p><pre>const userTimeZone = &quot;Africa/Johannesburg&quot;;<br><br>const authProvider = {<br>  getAccessToken: async () =&gt; {<br>    // Call getToken in auth.js<br>    return await getToken();<br>  },<br>};<br>// Initialize the Graph client<br>const graphClient = MicrosoftGraph.Client.initWithMiddleware({ authProvider });<br><br>async function getEvents() {<br>  ensureScope(&quot;Calendars.read&quot;);<br>  const dateNow = new Date();<br>  const dateNextWeek = new Date();<br>  dateNextWeek.setDate(dateNextWeek.getDate() + 7);<br>  const query = `startDateTime=${dateNow.toISOString()}&amp;endDateTime=${dateNextWeek.toISOString()}`;<br>  return await graphClient<br>    .api(&quot;/me/calendarView&quot;)<br>    .query(query)<br>    .header(&quot;Prefer&quot;, `outlook.timezone=&quot;${userTimeZone}&quot;`)<br>    .select(&quot;subject,start,end&quot;)<br>    .orderby(`Start/DateTime`)<br>    .get();<br>}</pre><p>We get the access token using the getToken method in the auth.js file. We then use the Microsoft Graph SDK (which we&#39;ll add later) to create a Microsoft Graph client that will handle Microsoft Graph API requests.</p><p>The getEvents function retrieves the user&#39;s calendar events for the next seven days. We use the ensureScope function to specify the permissions needed to access the calendar event data. We then call the &quot;/me/calendarview&quot; endpoint using the graphClient API method to get the data from Microsoft Graph. We create a query string and use the query method to get calendar events for the next seven days. The header method allows us to set our preferred time zone. Outlook Calendar event dates are stored using UTC. We need to set the time zone for the returned Outlook Calendar event start and end dates. This is done so that the correct event times are displayed in our Bryntum Calendar. Replace the value for the userTimeZone with the time zone value for your region. You can find the available strings <a href="https://learn.microsoft.com/en-us/graph/api/resources/datetimetimezone?view=graph-rest-1.0">here</a>.</p><p>We use the select method to select the properties in the results that our app will use. We only request the data that we need, which improves our app&#39;s performance.</p><p>The orderby method specifies how to sort the result items. We order the calendar data by the Start/DateTime field in ascending order. Ascending order is the default if the keywords asc or desc are not specified.</p><p>Now let’s add the user’s Outlook Calendar events to our Bryntum Calendar.</p><h3>Adding the Microsoft Outlook Calendar events to Bryntum Calendar</h3><p>Let’s add the Microsoft 365 sign in link and import the Microsoft Authentication Library and Microsoft Graph SDK. In the index.html file, replace the child elements of the &lt;body&gt; HTML element with the following elements:</p><pre>    &lt;main id=&quot;main-container&quot; role=&quot;main&quot; class=&quot;container&quot;&gt;<br>      &lt;div id=&quot;content&quot; style=&quot;display: none&quot;&gt;<br>        &lt;div id=&quot;calendar&quot;&gt;&lt;/div&gt;<br>      &lt;/div&gt;<br>      &lt;a id=&quot;signin&quot; href=&quot;#&quot;&gt;<br>        &lt;img<br>          src=&quot;./images/ms-symbollockup_signin_light.png&quot;<br>          alt=&quot;Sign in with Microsoft&quot;<br>        /&gt;<br>      &lt;/a&gt;<br>    &lt;/main&gt;<br>    &lt;script<br>      src=&quot;https://alcdn.msauth.net/browser/2.1.0/js/msal-browser.min.js&quot;<br>      integrity=&quot;sha384-EmYPwkfj+VVmL1brMS1h6jUztl4QMS8Qq8xlZNgIT/luzg7MAzDVrRa2JxbNmk/e&quot;<br>      crossorigin=&quot;anonymous&quot;<br>    &gt;&lt;/script&gt;<br>    &lt;script src=&quot;https://cdn.jsdelivr.net/npm/@microsoft/microsoft-graph-client/lib/graph-js-sdk.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;auth.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;graph.js&quot;&gt;&lt;/script&gt;<br>    &lt;script type=&quot;module&quot; src=&quot;main.js&quot;&gt;&lt;/script&gt;</pre><p>Initially, our app will display the sign-in link only. When a user signs in, the Bryntum Calendar will be displayed.</p><p>In the main.js file, add the following line to store the &quot;Sign in with Microsoft&quot; link element object in a variable:</p><pre>const signInButton = document.getElementById(&quot;signin&quot;);</pre><p>Now add the following function at the bottom of the file:</p><pre>async function displayUI() {<br>  await signIn();<br><br>  // Hide sign in link and initial UI<br>  signInButton.style = &quot;display: none&quot;;<br>  var content = document.getElementById(&quot;content&quot;);<br>  content.style = &quot;display: block&quot;;<br><br>  // Display calendar after sign in<br>  var events = await getEvents();<br>  var calendarEvents = [];<br>  var eventId = 1;<br>  var resourceID = 1;<br>  events.value.forEach((event) =&gt; {<br>    calendarEvents.push({<br>      id: eventId,<br>      name: event.subject,<br>      startDate: event.start.dateTime,<br>      endDate: event.end.dateTime,<br>      resourceId: resourceID,<br>    });<br>    eventId++;<br>  });<br>  calendar.events = calendarEvents;<br>}<br><br>signInButton.addEventListener(&quot;click&quot;, displayUI);<br><br>export { displayUI };</pre><p>The displayUI function calls the signIn function in auth.js to sign the user in. Once the user is signed in, the sign-in link is hidden and the Bryntum Calendar is displayed. We use the getEvents function in the graph.js file to get the calendar events for the next seven days. We then use the retrieved Outlook Calendar events to create calendar events for the Bryntum Calendar and add them to the calendar.events store.</p><p>Now sign in to <a href="https://www.microsoft.com/en-za/microsoft-365/outlook/email-and-calendar-software-microsoft-outlook">Microsoft Outlook</a> using the admin email address from your Microsoft 365 Developer Program account and create some events for the following week:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DXVhU3cXVHeBTmT9GplM1Q.png" /></figure><p>Run your dev server using npm run dev and you&#39;ll see the sign-in link:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SjQQvavlSaKIQuSTekgbPQ.png" /></figure><p>Sign in with the same admin email address that you used to log in to Microsoft Outlook:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C2ZZbyzt0hG847hDMnowug.png" /></figure><p>You’ll now see your Outlook Calendar events in your Bryntum Calendar:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rfJnKA6_xIOPr1qDhvwrCQ.png" /></figure><p>Next, we’ll sync the calendars by implementing CRUD functionality in our Bryntum Calendar. Updates to the Bryntum Calendar events will update the events in the Microsoft Outlook Calendar.</p><h3>Implementing CRUD</h3><p>Now that we have connected our calendar to the Graph API, we’ll implement CRUD functionality by taking advantage of Microsoft Graph’s post, get, patch, and delete methods, passing a query string where relevant.</p><h3>Create events</h3><p>In the graph.js file, add the following lines:</p><pre>async function createEvent(name, startDate, endDate) {<br>  ensureScope(&quot;Calendars.ReadWrite&quot;);<br>  const event = {<br>    subject: `${name}`,<br>    body: {<br>      contentType: &quot;HTML&quot;,<br>      content: &quot;This is a test event&quot;,<br>    },<br>    start: {<br>      dateTime: `${startDate.toISOString()}`,<br>      timeZone: userTimeZone,<br>    },<br>    end: {<br>      dateTime: `${endDate.toISOString()}`,<br>      timeZone: userTimeZone,<br>    },<br>  };<br>  return await graphClient.api(&quot;/me/events&quot;).post(event);<br>}</pre><p>Here we create a function that will create an Outlook event with a name, start date, and end date collected from the Bryntum Calendar. The function is passed the appropriate scope and the new event data is defined. The timezone needs to be specified otherwise Microsoft Graph will assume the timezone is GMT.</p><h3>Get all events</h3><p>In the graph.js file, add the following function:</p><pre>async function getAllEvents() {<br>  ensureScope(&quot;Calendars.ReadWrite&quot;);<br>  return await graphClient<br>    .api(&quot;/me/events&quot;)<br>    .select(<br>      &quot;id,subject,body,bodyPreview,organizer,attendees,start,end,location&quot;<br>    )<br>    .get();<br>}</pre><p>This function is similar to the getNextWeeksEvents function that we created earlier. The function is passed the appropriate scope, and we pass in an appropriate query string that filters the data to return only the event data appropriate to us. However, we will get all events from the user&#39;s calendar in this case.</p><p>We need all the events from the user’s calendar, as we will search through these events later on.</p><h3>Update events</h3><p>In the graph.js file, add the following function:</p><pre>async function updateEvent(id, name, startDate, endDate) {<br>  ensureScope(&quot;Calendars.ReadWrite&quot;);<br>  const event = {<br>    subject: `${name}`,<br>    body: {<br>      contentType: &quot;HTML&quot;,<br>      content: &quot;This is a test event&quot;,<br>    },<br>    start: {<br>      dateTime: `${startDate.toISOString()}`,<br>      timeZone: userTimeZone,<br>    },<br>    end: {<br>      dateTime: `${endDate.toISOString()}`,<br>      timeZone: userTimeZone,<br>    },<br>  };<br>  return await graphClient.api(`/me/events/${id}`).patch(event);<br>}</pre><p>The updateEvent function will identify the appropriate Outlook event by id, and then it will use the new name, start date, and end date from the Bryntum Calendar to update the event. The function is passed the appropriate scope, and the new event data is defined.</p><h3>Delete events</h3><p>In the graph.js file, add the following function:</p><pre>async function deleteEvent(id) {<br>  ensureScope(&quot;Calendars.ReadWrite&quot;);<br>  return await graphClient.api(`/me/events/${id}`).delete();<br>}</pre><p>The deleteEvent function will identify the appropriate Outlook event by id, and delete the event.</p><h3>Listening for event data changes in the Bryntum Calendar</h3><p>Next, we’ll set the listeners for our Bryntum Calendar so that it will know when the user updates the calendar events.</p><p>Replace the definition of calendar with the following code:</p><pre>const calendar = new Calendar({<br>  appendTo: &quot;calendar&quot;,<br><br>  listeners: {<br>    dataChange: function (event) {<br>      updateMicrosoft(event);<br>    },<br>  },<br><br>  resources: [<br>    {<br>      id: 1,<br>      name: &quot;Default Calendar&quot;,<br>      eventColor: &quot;green&quot;,<br>    },<br>  ],<br>});</pre><p>Here we set a listener on our Bryntum Calendar to listen for any changes to the Bryntum Calendar’s data store. This will fire an event called &quot;update&quot; whenever a calendar event is created or updated, and an event called &quot;remove&quot; whenever an event is deleted.</p><p>The event that’s retrieved from the dataChange listener will also carry event data about the specific calendar event that has been altered. We&#39;ll use the event data to identify which event is being altered and what&#39;s being changed.</p><p>In the main.js file, remove the following variables as we don&#39;t need them anymore:</p><pre>const startDate = new Date();<br>const endDate = new Date();<br>endDate.setHours(endDate.getHours() + 1);<br>const startDateStr = startDate.toISOString().substring(0, 19);<br>const endDateStr = endDate.toISOString().substring(0, 19);</pre><p>Next we’ll create a function called updateMicrosoft that will update the Outlook Calendar when the appropriate &quot;update&quot; or &quot;delete&quot; event is fired.</p><p>Add the following code below the definition of calendar in the main.js file:</p><pre>async function updateMicrosoft(event) {<br>  if (event.action == &quot;update&quot;) {<br>    const microEvents = await getAllEvents();<br>    // check if event exists in microsoft, if it does, update it, if not, create it<br>    var eventExists = false;<br><br>    for (var i = 0; i &lt; microEvents.value.length; i++) {<br>      // event exists in both microsoft and bryntum with the same name<br>      if (microEvents.value[i].subject == event.record.name) {<br>        eventExists = true;<br>        updateEvent(<br>          microEvents.value[i].id,<br>          event.record.name,<br>          event.record.startDate,<br>          event.record.endDate<br>        );<br>        return;<br>      } else if (&quot;name&quot; in event.changes) {<br>        if (event.changes.name.oldValue == microEvents.value[i].subject) {<br>          eventExists = true;<br>          updateEvent(<br>            microEvents.value[i].id,<br>            event.record.name,<br>            event.record.startDate,<br>            event.record.endDate<br>          );<br>          return;<br>        }<br>      } else if (&quot;resourceId&quot; in event.changes) {<br>        eventExists = true;<br>      }<br>    }<br>    // event does not exist in microsoft, create it<br>    if (!eventExists) {<br>      if (event.record.name != undefined) {<br>        createEvent(<br>          event.record.name,<br>          event.record.startDate,<br>          event.record.endDate<br>        );<br>      }<br>    }<br>  }<br>  // event is deleted<br>  else if (event.action == &quot;remove&quot;) {<br>    const microEvents = await getAllEvents();<br>    var eventName = event.records[0].data.name;<br>    for (var i = 0; i &lt; microEvents.value.length; i++) {<br>      if (microEvents.value[i].subject == eventName) {<br>        deleteEvent(microEvents.value[i].id);<br>        return;<br>      }<br>    }<br>  }<br>}</pre><p>Here we create a function that is called on all changes to the data store of the Bryntum Calendar. The function then calls one of the Microsoft Graph CRUD functions that we defined.</p><p>On &quot;update&quot; we call getAllEvents to get a list of all the user&#39;s Outlook Calendar events. We then loop through this list and compare the Bryntum Calendar event data from the &quot;update&quot; event to the Microsoft events.</p><pre>async function updateMicrosoft(event) {<br>  if (event.action == &quot;update&quot;) {<br>    const microEvents = await getAllEvents();<br>    // check if event exists in microsoft, if it does, update it, if not, create it<br>    var eventExists = false;<br><br>    for (var i = 0; i &lt; microEvents.value.length; i++) {</pre><p>If there are events that match by name, then that Microsoft event needs to be updated.</p><pre>// event exists in both microsoft and bryntum with the same name<br>      if (microEvents.value[i].subject == event.record.name) {<br>        eventExists = true;<br>        updateEvent(<br>          microEvents.value[i].id,<br>          event.record.name,<br>          event.record.startDate,<br>          event.record.endDate<br>        );<br>        return;</pre><p>But if the name has been changed, there won’t be a match. We need to check if any of the Microsoft event names match the name found in the “oldData” of the update data. This oldName data represents the name before the change made by update.</p><p>If a Microsoft event name matches the name in the “oldData”, then that Microsoft event needs to be updated to match the name.</p><pre>} else if (&quot;name&quot; in event.changes) {<br>        if (event.changes.name.oldValue == microEvents.value[i].subject) {<br>          eventExists = true;<br>          updateEvent(<br>            microEvents.value[i].id,<br>            event.record.name,<br>            event.record.startDate,<br>            event.record.endDate<br>          );<br>          return;</pre><p>Next, we check the event.changes for a resource ID. If this resource ID exists, then the change has already been made and this update event should be ignored.</p><pre>} else if (&quot;resourceId&quot; in event.changes) {<br>        eventExists = true;<br>      }</pre><p>If the update passes any of these tests, then eventExists will be set to true. If not, then it will be set to false and the createEvent function will be triggered.</p><p>If no Microsoft event matches it, it’s because a new event was created in the Bryntum Calendar, so we create a new Outlook event using this new data.</p><pre>// event does not exist in microsoft, create it<br>    if (!eventExists) {<br>      if (event.record.name != undefined) {<br>        createEvent(<br>          event.record.name,<br>          event.record.startDate,<br>          event.record.endDate<br>        );<br>      }<br>    }</pre><p>Finally, if the dataChange event is a &quot;remove&quot; event, then we delete the matching Outlook event using the deleteEvent function.</p><pre>// event is deleted<br>  else if (event.action == &quot;remove&quot;) {<br>    const microEvents = await getAllEvents();<br>    var eventName = event.records[0].data.name;<br>    for (var i = 0; i &lt; microEvents.value.length; i++) {<br>      if (microEvents.value[i].subject == eventName) {<br>        deleteEvent(microEvents.value[i].id);<br>        return;<br>      }<br>    }<br>  }</pre><p>Now try to create, update, delete, and edit an event in the Bryntum Calendar. You’ll see the changes reflected in the Outlook Calendar.</p><h3>Next steps</h3><p>This tutorial gives you a starting point for creating a Bryntum Calendar using vanilla JavaScript and syncing it with Microsoft Outlook. There are many ways that you can improve the Bryntum Calendar. For example, you can add features such as <a href="https://bryntum.com/examples/calendar/resourceview/">per-resource calendar views</a>. Take a look at our <a href="https://bryntum.com/examples/calendar/">Calendar demos page</a> to see demos of the available features.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67da24a10241" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bryntum/how-to-connect-and-sync-bryntum-calendar-to-a-microsoft-outlook-calendar-67da24a10241">How to connect and sync Bryntum Calendar to a Microsoft Outlook Calendar</a> was originally published in <a href="https://medium.com/bryntum">Bryntum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a property management scheduler with Bryntum using vanilla JavaScript]]></title>
            <link>https://medium.com/bryntum/create-a-property-management-scheduler-with-bryntum-using-vanilla-javascript-54f8bbfbe2ca?source=rss----32ca805267d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/54f8bbfbe2ca</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-components]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[scheduling]]></category>
            <dc:creator><![CDATA[Mats Bryntse]]></dc:creator>
            <pubDate>Thu, 13 Oct 2022 13:00:08 GMT</pubDate>
            <atom:updated>2022-10-13T21:08:33.368Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e_tj_Auy_D0xkNCsA0O84g.png" /></figure><h3>Creating a property management scheduler with Bryntum using vanilla JavaScript</h3><p>The <a href="https://www.bryntum.com/products/scheduler/">Bryntum Scheduler</a> component is a JavaScript resource management widget you can use to manage complex schedules. It is feature-packed with great performance, and you can customize it to suit your needs. In this tutorial, we will create a property management app to keep track of bookings for different rental apartments using the Bryntum Scheduler. Our vanilla JavaScript scheduler will have the following features:</p><ul><li>The properties have different prices per night, and dates can be set aside when a property is not available to be booked.</li><li>The user can add new bookings by clicking and dragging their cursor in empty parts of the scheduler rows. The price of the stay will automatically be calculated based on the number of days and price per night.</li><li>Booking dates can’t overlap.</li><li>The user can set the details for the booking: The client’s name, the duration of the stay, price, and number of guests.</li><li>A summary row to show the number of bookings or number of guests per day. The user can toggle between the summary options using buttons at the top of the scheduler. Multiple property rows can be selected to calculate the combined summary row values for the selected properties.</li></ul><p>Once you’re done, you’ll have a property management scheduler that looks like the one shown in the image below and in this short <a href="https://www.youtube.com/watch?v=amGp3oLHIPw">demo video</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FamGp3oLHIPw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DamGp3oLHIPw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FamGp3oLHIPw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/14263063066a79c632c769a08b39b609/href">https://medium.com/media/14263063066a79c632c769a08b39b609/href</a></iframe><p>Or you can try the <a href="https://bryntum.com/examples/scheduler/booking/">live demo here</a>.</p><h3>Getting started</h3><p>To get started, we’ll follow the steps outlined in the following guide from the Bryntum docs: <a href="https://www.bryntum.com/docs/scheduler/guide/Scheduler/quick-start/javascript">Getting Started on Bryntum Scheduler with Vanilla JS</a>. We will use files from the trial distribution folder. If you want to use npm instead, you can follow this <a href="https://www.bryntum.com/docs/scheduler/guide/Scheduler/quick-start/javascript-npm">guide</a> from the docs.</p><p>Download the free trial version distribution folder of the Bryntum version 5.2.0 Scheduler <a href="https://bryntum.com/download">here</a>. If you have already bought the licensed version, you can log in <a href="https://customerzone.bryntum.com/">here</a> to get it.</p><p>Unzip the downloaded distribution folder on your PC. We’ll make use of the following folders to make our property management app:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52c8f70a6632df1c54baa391bf35e8ee/href">https://medium.com/media/52c8f70a6632df1c54baa391bf35e8ee/href</a></iframe><p>We’ll copy files and folders from these into a new folder for our property management scheduler app. In the root folder of your project, create a folder called schedulerDist and add the following files and folders from the Bryntum Scheduler distribution folder:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*79JjL2CWbk-E8gGMPLoUVg@2x.png" /></figure><p>In the examples folder, we only need the browser folder and the shared.css, shared.css.map, and shared.scss files.</p><p>Now add the following files and folders from the Bryntum Scheduler distribution folder /examples/booking/ folder to the root folder of your project. This is the folder that contains the code for the demo that we’ll create in this tutorial:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*J0HCnkmTkPq7tu-auv2nsA@2x.png" /></figure><p>In the lib folder, replace file imports in DailyRate.js, DaySelector.js, PropertyModel.js and ReservationModel.js as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be99a15fd25e718bbbbc29398e05563b/href">https://medium.com/media/be99a15fd25e718bbbbc29398e05563b/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df0d7247edcdf1688cbd717effae4ee8/href">https://medium.com/media/df0d7247edcdf1688cbd717effae4ee8/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56b549d2e7d8253af9021ec1b6efb574/href">https://medium.com/media/56b549d2e7d8253af9021ec1b6efb574/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed32e88e97d09fd58bde503b1e2a26f6/href">https://medium.com/media/ed32e88e97d09fd58bde503b1e2a26f6/href</a></iframe><p>In the resources folder, do the following find and replace for the file imports:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*Mv-7hdr-XJelPDeFPBegIg@2x.png" /></figure><p>Create an index.html file in your app’s root folder and add the following lines to it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f3e94f55504470dae1c8fce416c1c1e/href">https://medium.com/media/9f3e94f55504470dae1c8fce416c1c1e/href</a></iframe><p>Now create an app.js file in your app’s root folder. We’ll only need to work in this file from now on to create our property management scheduler.</p><p>We use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules">JavaScript modules</a> to split the code into separate modules that can be imported and exported, so we’ll need a local HTTP server to run the code. To get a local server with live reload, you can install the npm <a href="https://www.npmjs.com/package/live-server">Live Server</a> package. If you are using VS Code, you can install the <a href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer">Live Server</a> extension.</p><h3>Creating a Scheduler instance</h3><p>To create a scheduler, let’s first import all of the classes that we’ll need from the schedulerDist/build/ folder and the lib folder in the root of our app:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/875ccfc6c251632b8b5b608b917536db/href">https://medium.com/media/875ccfc6c251632b8b5b608b917536db/href</a></iframe><p>Now let’s create an instance of our scheduler and configure it with inline properties:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eea1fa799fa779eb1b119ed24bd40a1a/href">https://medium.com/media/eea1fa799fa779eb1b119ed24bd40a1a/href</a></iframe><p>The appendTo property indicates the id of the DOM element that the scheduler will be added to as a child element. In the index.html file, there is a &lt;div&gt; element with an id of container.</p><p>If you open the development server in your browser now, you’ll now see the Bryntum Scheduler:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1XxBMq-nqXhD4LxgyWPKUw.png" /></figure><p>We’ll now proceed to configure our scheduler with more properties to make it a useful booking management app.</p><h3>Setting the date range and columns</h3><p>Let’s set the date range displayed at the top of the scheduler and create a column for our resources, which will be our accommodation properties.</p><p>Add the following properties to the scheduler:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96fe4d28947899f3ad24b190a5f845f4/href">https://medium.com/media/96fe4d28947899f3ad24b190a5f845f4/href</a></iframe><p>The viewPreset describes the type of timeline view. In this case, we’ll use a day and month view for the calendar. The resourceImagePath contains the accommodation property images that will be displayed in the property column we’ll create. We set the start and end date of the calendar view using JavaScript <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date">Date</a> objects.</p><p>Add the following columns property to define our accommodation property:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa22237eead1d09acce3102c3575f321/href">https://medium.com/media/aa22237eead1d09acce3102c3575f321/href</a></iframe><p>We set the type to ’<a href="https://www.bryntum.com/docs/scheduler/api/Scheduler/column/ResourceInfoColumn">resourceInfo</a>’ to display the basic information for our scheduler resource, which will be the accommodation properties.</p><p>You’ll now see a “PROPERTY” column in your scheduler and the calendar header will be nicely formatted:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jn6xPiLLF-4EvzF7pPFiCg.png" /></figure><h3>Getting data using the Crud Manager</h3><p>The Scheduler includes a <a href="https://www.bryntum.com/docs/scheduler/guide/Scheduler/data/crud_manager">crudManager</a> for loading and saving remote data. It has a loadUrl property that we’ll use to populate the scheduler’s data stores. Add the following crudManager property to your scheduler:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6aac7f63aef6b4b055cb074e88f697f0/href">https://medium.com/media/6aac7f63aef6b4b055cb074e88f697f0/href</a></iframe><p>The loadUrl property defines the url data source, which is the data.json file in the data folder. You can also configure the crudManager to sync data changes to a specific back end url. For more information, you can read the following guide in our docs: <a href="https://www.bryntum.com/docs/scheduler/guide/Scheduler/data/crud_manager#saving-data">Saving data</a>.</p><p>We also define the three data stores that we’ll use. They make use of models and stores defined in the ./lib folder. The resourceStore holds the data for our accommodation properties. It uses the custom PropertyModel that extends the scheduler <a href="https://www.bryntum.com/docs/scheduler/api/Scheduler/model/ResourceModel">ResourceModel</a>. It adds an extra sleeps field to it. This extra property is used in the data/data.json file in the resources rows. It defines the number of people that each property can accommodate.</p><p>The eventStore holds the data for our bookings. It uses the custom ReservationModel that extends the scheduler <a href="https://www.bryntum.com/docs/scheduler/api/Scheduler/model/EventModel">EventModel</a>. It adds the extra fields guests and pricePerNight. These extra properties are used in the data/data.json file in the events rows.</p><p>The resourceTimeRangeStore holds the data for the resource time ranges that are used to display prices per date and property in the calendar part of our scheduler. The DailyRateStore class extends the scheduler <a href="https://www.bryntum.com/docs/scheduler/api/Scheduler/data/mixin/RecurringTimeSpansMixin">RecurringTimeSpansMixin</a> class that adds recurring time spans functionality to the scheduler. It uses the DailyRateModel model that has a pricePerNight field. It also has a getPricePerNightFor method that we’ll use to get the price per night for an accommodation property when we create a new booking on a particular date.</p><p>In the data/data.json file, the resourceTimeRanges rows have a pricePerNight field and a <a href="https://www.bryntum.com/docs/scheduler/api/Scheduler/model/mixin/RecurringTimeSpan#field-recurrenceRule">recurrenceRule</a> that describes the days on which the prices are applied. There is also an <a href="https://www.bryntum.com/docs/scheduler/api/Scheduler/model/mixin/RecurringTimeSpan#field-exceptionDates">exceptionDates</a> field that shows days where no prices should be applied. These indicate days when the property is not available for booking.</p><p>You’ll now see the properties and bookings in your booking scheduler app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NiDs47EALrvivAQDrmrM5Q.png" /></figure><p>The prices per date and property are not rendered. Let’s fix that.</p><h3>Displaying the prices per date and property</h3><p>First, let’s increase the row height and the bar margin of the bookings. Add the following properties to your scheduler:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69e33d4dbcdb5ebb2b155b3a52de19ff/href">https://medium.com/media/69e33d4dbcdb5ebb2b155b3a52de19ff/href</a></iframe><p>Now add the following features property to your scheduler:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62c103228d001047f95791a9f79bbd3a/href">https://medium.com/media/62c103228d001047f95791a9f79bbd3a/href</a></iframe><p>The <a href="https://www.bryntum.com/docs/scheduler/api/Scheduler/feature/TimeRanges">timeRanges</a> property is used to visualize a time range. In this case, it simulates shading time in the past. The time range rendered is defined in the timeRanges property in the data/data.json file. It has a <a href="https://www.bryntum.com/docs/scheduler/api/Core/widget/Widget#property-cls">cls</a> property, which is a custom CSS class. The shaded class is defined in resources/app.css.</p><p>Now add the following three properties to your scheduler, below the endDate property:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2df99fe767398bdba816806a9c6efade/href">https://medium.com/media/2df99fe767398bdba816806a9c6efade/href</a></iframe><p>The zoomOnTimeAxisDoubleClick and zoomOnMouseWheel properties prevent zooming in or out of the current calendar view. The allowOverlap property prevents bookings from overlapping. Try moving a booking to a date where there’s another booking in your property management scheduler app. It won’t work. Also, you can’t move any bookings in the shaded area. The shaded layer is meant to prevent moving events in the past.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P8m2UWFMq0LbO4AHZ7y_nQ.gif" /></figure><p>You can extend the duration of a booking by dragging the sides of the booking bar. We can improve the user experience of this by making the booking bar width increment by one-day units when it’s resized. Add the following properties to the scheduler below the barMargin property:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bbe05367f4583bc0e12691c715d2e24/href">https://medium.com/media/1bbe05367f4583bc0e12691c715d2e24/href</a></iframe><p>Now when you resize the booking, the width will increment to the next day. You can’t, for example, have a half-day booking.</p><p>You may notice that we aren’t able to add new bookings yet. Let’s add this feature.</p><h3>Adding a custom add booking feature</h3><p>Let’s add a custom feature to allow a user to add new bookings by clicking and dragging their cursor in empty parts of the scheduler rows. The price of the stay will automatically be calculated based on the number of days and price per night. A tooltip will show the calculated cost and the duration of the stay while creating the booking.</p><p>Add the following property to your scheduler inside the features property:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c863044362e2012871bb32683f2a4b15/href">https://medium.com/media/c863044362e2012871bb32683f2a4b15/href</a></iframe><p>The class that defines this custom feature is in lib/DaySelector.js.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fVBJFK-h91lSgxNf7ucY-g.gif" /></figure><p>Try adding an event. You’ll notice that an event editor pops up. You can also access the event editor by right-clicking on an existing booking. The event editor does not contain all the fields we need yet, such as the number of guests. We’ll customize this next.</p><h3>Customizing the edit event pop-up menu</h3><p>To customize the edit event pop-up, we’re going to use the <a href="https://www.bryntum.com/docs/scheduler/api/Scheduler/feature/EventEdit">eventEdit</a> feature. Add the following eventEdit feature to your scheduler inside the features property:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd3b6413395de2af5e8e5bc714980e86/href">https://medium.com/media/fd3b6413395de2af5e8e5bc714980e86/href</a></iframe><p>We set the fields that we don’t want to false and define the fields that we want. For the “NIGHTS” and “NUMBER OF GUESTS” fields, we set a min of one. The “NUMBER OF GUESTS” field has a default value of two and is a required field.</p><p>Let’s also disable some features that we don’t need for this tutorial. Add the following properties inside the features property:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83ba45c1a668ffa2a09ecb7ccd0ecd2c/href">https://medium.com/media/83ba45c1a668ffa2a09ecb7ccd0ecd2c/href</a></iframe><p>If you create a booking now, you’ll notice that the “PRICE PER NIGHT (USD)” field is empty. Let’s get it to auto-populate the price per night for the first day booked. Add the following method to your scheduler, below the crudManager property:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11fb25720ccde4721699bead74aba1b2/href">https://medium.com/media/11fb25720ccde4721699bead74aba1b2/href</a></iframe><p>The <a href="https://www.bryntum.com/docs/scheduler/api/Scheduler/view/SchedulerBase#event-beforeEventAdd">beforeEventAdd</a> event runs before an event is added. We add the price per night to the <a href="https://www.bryntum.com/docs/scheduler/api/Scheduler/feature/EventEdit#property-eventRecord">eventRecord</a> by using the getPricePerNightFor method defined in lib/DailyRateStore.js.</p><p>Now if you add a task, you’ll see that the “PRICE PER NIGHT (USD)” field is auto-populated.</p><h3>Changing the booking bar text</h3><p>The booking bar currently only displays the guest name. Let’s change it so that it also displays the number of guests.</p><p>Add the following eventRenderer method to your scheduler below the onBeforeEventAdd method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b44da99e1935e30869000a6bf1b7863d/href">https://medium.com/media/b44da99e1935e30869000a6bf1b7863d/href</a></iframe><p>The <a href="https://www.bryntum.com/docs/scheduler/api/Scheduler/view/mixin/SchedulerEventRendering#config-eventRenderer">eventRenderer</a> function is called when an event is rendered in the scheduler. A string is returned that creates HTML that is rendered on the booking bar. We add the name of the booking and the number of guests. We use the <a href="https://fontawesome.com/">Font Awesome</a> user icon to indicate the number of guests. The version of Font Awesome used by Bryntum has a b-fa prefix instead of fa to prevent conflicts with other versions of Font Awesome on the page. The source of these icons is in schedulerDist/build/fonts and they are imported as a font-face in /schedulerDist/build/scheduler.stockholm.css.</p><p>You’ll now see a user icon on the booking bar with a number indicating the number of guests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*tLNBeKrRTFDGBlH4LNv2DQ.png" /></figure><h3>Customizing the event tooltip</h3><p>When you hover over a booking, a default tooltip will appear that shows the start and end date of the booking. Let’s customize it to display the check-in date and the duration of the stay. Add the following eventTooltip feature to your scheduler inside the features property:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8ee8d926c0a88bc1f411b448aaabd0d/href">https://medium.com/media/d8ee8d926c0a88bc1f411b448aaabd0d/href</a></iframe><p>The <a href="https://www.bryntum.com/docs/scheduler/api/Scheduler/feature/EventTooltip">eventTooltip</a> feature allows you to customize the template used to render the tooltip. The <a href="https://www.bryntum.com/docs/scheduler/api/Scheduler/feature/EventTooltip#config-template">template</a> method receives data about an event as arguments. We use the eventRecord argument to render a string displaying the data we want about the booking.</p><h3>Adding a summary row</h3><p>The last feature we’ll add is a summary row showing the number of bookings or number of guests per day.</p><p>Add the following summary feature to your scheduler inside the features property:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c746f567ea3cd976768a323c2e86d717/href">https://medium.com/media/c746f567ea3cd976768a323c2e86d717/href</a></iframe><p>The <a href="https://www.bryntum.com/docs/scheduler/api/Grid/feature/Summary">summary</a> feature displays a summary row in the grid footer. It renders the number of reservations or the total number of guests, depending on the value of the summaryButton group that we’ll soon create.</p><p>Let’s create a <a href="https://www.bryntum.com/docs/scheduler/api/Core/widget/Panel#property-tbar">toolbar</a> at the top of our scheduler that has a summaryButton group with a togglable value. Add the following property to your scheduler:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d48bab2baa365c0ab6eb2823d4d2ad1/href">https://medium.com/media/0d48bab2baa365c0ab6eb2823d4d2ad1/href</a></iframe><p>The summaryButton has a togglable value that is either count or guests. When one of them is clicked, the value is updated by refreshing the summary feature value.</p><p>There is also a “Sum selected rows” button that allows us to calculate the number of booked properties or guests for selected rows only. For it to work, we need to define the onSumToggle method. Add the following onSumToggle method to your scheduler below the eventRenderer method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e66635db7c78973c86f3bdcd4b982e0/href">https://medium.com/media/1e66635db7c78973c86f3bdcd4b982e0/href</a></iframe><p>Now you’ll be able to determine the number of booked properties or guests per day for the whole scheduler or selected rows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XZZBV5dKJgnCUDRHk8bdTg.gif" /></figure><h3>Next steps</h3><p>This tutorial gives you a starting point for building your own <a href="https://bryntum.com/examples/scheduler/booking/">property management scheduler </a>with Bryntum using vanilla JavaScript. There are many ways you can add to or improve the property management scheduler. For example, a good additional feature to add would be to limit the number of guests for a booking based on the max number of people that a property can accommodate. If you have any questions on this tutorial or if you built something similar we would love to hear your feedback.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54f8bbfbe2ca" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bryntum/create-a-property-management-scheduler-with-bryntum-using-vanilla-javascript-54f8bbfbe2ca">Create a property management scheduler with Bryntum using vanilla JavaScript</a> was originally published in <a href="https://medium.com/bryntum">Bryntum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with CSS Container Queries — Bryntum]]></title>
            <link>https://medium.com/bryntum/getting-started-with-css-container-queries-bryntum-440e420578fe?source=rss----32ca805267d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/440e420578fe</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Mats Bryntse]]></dc:creator>
            <pubDate>Fri, 23 Sep 2022 13:04:30 GMT</pubDate>
            <atom:updated>2022-09-23T13:04:20.631Z</atom:updated>
            <content:encoded><![CDATA[<h3>Getting Started with CSS Container Queries — Bryntum</h3><p>If you’ve designed a responsive website in CSS, you’ve probably used <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries">media queries</a>. Media queries have always been the go-to and only solution for responsive and adaptable styling, whether that’s for detecting user preferences (like dark mode or reduced motion) or display size. That said, it doesn’t mean they are suitable for every scenario.</p><p>What if, instead of adapting the content to the viewport size, you want it to adapt to the container to create a component with a flexible layout? In this case, media queries can be pretty limiting. For responsiveness, you need separate media queries for every part of the layout, making the code much more cumbersome. That’s where container queries come in.</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Container_Queries">Container queries</a> are an upcoming feature of CSS that’s currently a working draft specification, with only experimental support from the browsers (at the time of writing). They’re meant to allow you to create responsive designs based on the parent element’s (container’s) size rather than the viewport. That said, it’s easy to see why this feature draws developers’ attention.</p><p>In this article, you’ll get to know container queries and how you can use them.</p><h3>Why You Need Container Queries</h3><p>In the era of component-based UI frameworks, more often than not, developers want their components to adapt to their parent elements, aka containers, rather than the entire viewport. Such an approach allows more flexibility as you can reuse the same component while adapting it to different placements, effectively decoupling responsiveness from the viewport. For example, you could have an e-commerce site with a product grid on the main page and a single <strong>Recommended products</strong> row on every product page, both in a single component.</p><p>Container queries are meant precisely for this kind of use case. By using them, you can easily define different styling for the element only when its container matches the provided constraints, similar to how media queries allow you to define styling based on viewport size:</p><pre>.item { <br>    display: flex; <br>    justify-content: center; <br>    align-items: center; flex-direction: column; <br>} </pre><pre>@container (min-width: 600px) { .item { flex-direction: row; } }</pre><p>To see how easy and convenient container queries are, compare them directly with media queries in a working demo.</p><h3>Getting Started with Container Queries</h3><p>To get started with container queries, you need to ensure you have a <a href="https://caniuse.com/css-container-queries">compatible browser</a> and the required feature flags turned on.</p><p>For this demo, you’ll use the CSS grid layout, which is often combined with media queries to build responsive views. Keep in mind that the same technique can be used with other layouts, like <a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox">flexbox</a>.</p><p>To start, create a simple CSS grid layout that adapts the number of columns to viewport size with the help of media queries:</p><pre>.grid-container { <br>    display: flex; <br>    justify-content: center; <br>    align-items: flex-start; <br>} </pre><pre>.grid { <br>     display: grid; <br>     gap: 1rem; <br>     padding: 1rem; <br>     grid-template-columns: repeat(1, minmax(0, 1fr)); <br>} </pre><pre>@media (min-width: 560px) { <br>    .grid { <br>         grid-template-columns: repeat(2, minmax(0, 1fr)); <br>    } <br>} </pre><pre>@media (min-width: 832px) { <br>    .grid { <br>        grid-template-columns: repeat(3, minmax(0, 1fr)); <br>    } <br>} </pre><pre>@media (min-width: 1104px) { <br>    .grid {   <br>        grid-template-columns: repeat(4, minmax(0, 1fr)); <br>    } <br>} </pre><pre>@media (min-width: 1376px) { <br>    .grid { <br>        grid-template-columns: repeat(5, minmax(0, 1fr));<br>    } <br>} </pre><pre>.item { height: 16rem; width: 16rem; /* ... */ }</pre><p>With this CSS, the grid works as intended, adapting to the viewport at each one of the five breakpoints. For example, here’s the grid at the largest viewport size, over 1376 px in width:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*A_Uz4i31bCrEJWQZ.png" /></figure><p>And here’s the same grid at less than 1104 px viewport width:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xQ49kSeM6iYopyUn.png" /></figure><p>Imagine this grid represents a list of products, blog posts, or photos. Even in the basic web apps, you’ll need to present this kind of content in several ways (grids, lists, carousels, etc.) and in many different places (main view, sidebar, search box, etc.). For this purpose, you’ll likely extract this part of the UI into a separate component. However, that’s where things start to get complicated.</p><p>What if you’d like to place the same component as a column next to the main grid view? In this case, using it as is would be less than ideal, resulting in the entire UI being broken:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xPHc2kXbEvT6xoBu.png" /></figure><p>The only solution would be to introduce a new class name like .grid-vertical that forces a single-column layout:</p><pre>.grid-vertical { grid-template-columns: repeat(1, minmax(0, 1fr)); }</pre><p>Now, this approach isn’t ideal. First off, it requires you to either add a vertical prop, making the component more complex and less flexible, or you have to create an entirely separate component that only differs in styling while duplicating the logic.</p><p>On top of that, this solution works well only at specific viewport sizes (separate layouts highlighted with different colors):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*k7IhrK6TdRY2km4W.png" /></figure><p>The minute viewport is resized, and the UI breaks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fAF6y60GvYuhLB6q.png" /></figure><p>All the media queries for the grid layout need to be updated, with consideration of the new limited viewport. Adding such code is cumbersome and, again, either makes the component unnecessarily complex or necessitates an entirely separate component. More code, decreased readability, and more challenging maintenance are all issues that you could avoid by using container queries.</p><h3>Implementing Container Queries</h3><p>To see how container queries can fix the mentioned issues, you’ll need to first wrap your layouts in separate containers:</p><pre>.grid-container { <br>    display: flex; <br>    justify-content: center; <br>    align-items: flex-start; <br>    container-type: size; <br>}</pre><p>On top of basic styling properties, you’ll have to include a container-type property. It defines the element as a query container, allowing its descendants to query its properties. It can have different values to indicate what <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Container_Queries#container-type_2">type of query container</a> you want: size, inline-size, style, and so forth. Since you&#39;ll be querying the container&#39;s dimensions, use size.</p><p>Alternatively, instead of container-type, you can use the container property, which is a shorthand for container-type and container-name:</p><pre>.grid-container { /* ... */ container: size my-container; }</pre><p>The container-name property allows you to set a custom name for the container to target it directly in case the element has multiple query containers, like so:</p><pre>.grid-container { /* ... */ container-name: my-container; }</pre><p>With containers ready, all you need to do is change the @media queries to @container:</p><pre>@container (min-width: 560px) { <br>     .grid { <br>         grid-template-columns: repeat(2, minmax(0, 1fr)); <br>     } <br>} </pre><pre>@container (min-width: 832px) { <br>    .grid { <br>         grid-template-columns: repeat(3, minmax(0, 1fr)); <br>    } <br>} </pre><pre>@container (min-width: 1104px) { <br>    .grid { <br>        grid-template-columns: repeat(4, minmax(0, 1fr)); <br>    } <br>} </pre><pre>@container (min-width: 1376px) { <br>     .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } <br>}</pre><p>In case you’ve specified a container-name ( <em>eg</em> my-container), you can query the specific container directly by using the following syntax:</p><pre>@container my-container (min-width: 560px) { <br>     .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } <br>}</pre><p>Now, all the styles will apply based on container size, which fixes all the previous issues with media queries:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IrvS0FaPwqlGpO3d.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7AOdwZnW1Ouxski2.png" /></figure><p>Thanks to the use of container queries, you now have a single component that easily adapts to the available space. For you, this translates to less code, more flexibility, and faster development.</p><p>If you have a compatible browser and the required feature flags turned on, you can preview the working demo <a href="https://codepen.io/areknawo/pen/gOezMwO">at this CodePen</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fareknawo%2Fembed%2Fpreview%2FgOezMwO%3Fdefault-tabs%3Dcss%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DgOezMwO&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fareknawo%2Fpen%2FgOezMwO&amp;image=https%3A%2F%2Fshots.codepen.io%2Fareknawo%2Fpen%2FgOezMwO-512.jpg%3Fversion%3D1659698623&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/011ed940260a4985d275a89bb67687a3/href">https://medium.com/media/011ed940260a4985d275a89bb67687a3/href</a></iframe><h3>Conclusion</h3><p>When container queries become an official part of the CSS specification, they’ll massively help developers create more flexible and responsive components. As you’ve seen, container queries are easy to use and serve to improve maintainability and development experience while working with CSS. Are you already using container queries today? We would love to hear your feedback on how it changes the way you write your web apps.</p><p><strong>This article was written in cooperation with Arek Nawo.</strong></p><p><em>Bryntum helps the world stay on schedule. Our component library offers a selection of high-quality, advanced UI controls for various frontend frameworks. Want to learn more? Try our scheduling and Gantt components at </em><a href="https://www.bryntum.com/"><em>bryntum.com</em></a><em>.</em></p><p><em>Originally published at </em><a href="https://www.bryntum.com/blog/getting-started-with-css-container-queries/"><em>https://www.bryntum.com</em></a><em> on September 23, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=440e420578fe" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bryntum/getting-started-with-css-container-queries-bryntum-440e420578fe">Getting Started with CSS Container Queries — Bryntum</a> was originally published in <a href="https://medium.com/bryntum">Bryntum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Gantt chart with React using Next.js]]></title>
            <link>https://medium.com/bryntum/creating-a-gantt-chart-with-react-using-next-js-fc080ad8b938?source=rss----32ca805267d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/fc080ad8b938</guid>
            <category><![CDATA[gantt-chart]]></category>
            <category><![CDATA[gantt]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Saki]]></dc:creator>
            <pubDate>Tue, 13 Sep 2022 13:07:29 GMT</pubDate>
            <atom:updated>2022-09-20T12:34:52.506Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZgIRyhwkSUnu7xIPxHpa_Q.png" /></figure><p>A Gantt chart is a project management tool for coordinating complex schedules for large or multiple teams. Using a Gantt chart that is JavaScript-based has a couple of advantages over spreadsheet-based Gantt charts, such as:</p><ul><li>Easy integration into existing project management dashboards.</li><li>Sharing your chart online.</li><li>Customizing your chart to suit your needs.</li></ul><p>In a <a href="https://www.bryntum.com/blog/creating-a-gantt-chart-with-vanilla-javascript/">previous article</a>, we described how to make a basic drag-and-drop Gantt chart component using vanilla JavaScript. In this article, we’ll make the same basic Gantt chart with React using Next.js.</p><p>We’ll also create a basic Gantt chart using our commercial <a href="https://bryntum.com/examples/gantt">Bryntum Gantt Chart</a> and look at the differences between building your own chart versus using an off-the-shelf solution.</p><p>The basic React Gantt chart that we’ll create using Next.js will have the following features:</p><ul><li>The user can select the planning time period by selecting a start date and an end date.</li><li>We’ll be able to add, delete, and edit tasks.</li><li>Task durations can be added and deleted, and we’ll be able to edit them using drag and drop.</li></ul><p>Once you’re done, you’ll have a Gantt chart that looks like the one shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8rPRxn4OeNQsyAeqXwhEFg@2x.png" /></figure><p>You can find the code for the completed Next.js Gantt Chart in <a href="https://github.com/bryntum/gantt-chart-nextjs-starter/tree/complete-chart">our GitHub repository</a>.</p><h3>Getting started</h3><p>We’ll start this project by cloning the following <a href="https://github.com/bryntum/gantt-chart-nextjs-starter/tree/main">Next.js Gantt chart starter GitHub repository</a>.</p><p>The .vscode folder includes some VS Code settings and extension recommendations, as well as settings for <a href="https://eslint.org/">ESLint</a> and <a href="https://prettier.io/">Prettier</a>. ESLint and Prettier have been added and configured to format your code on paste and on save. If you don’t use VS Code as an IDE, you’ll need to configure these for your IDE. Once you’ve done that, you can delete this folder.</p><p>The starter repository contains all the components you’ll need to create the Gantt chart. You’ll need to create some state and complete the code for the components. The code used is similar to our <a href="https://www.bryntum.com/blog/creating-a-gantt-chart-with-vanilla-javascript/">previous article</a> that explains how to make a vanilla JavaScript Gantt Chart.</p><p>If you install dependencies npm install and run the local development server using npm run dev, you’ll see a page with the header “Gantt Tracker”.</p><p>Let’s take a look at how the Gantt chart starter code is structured.</p><h3>Adding styling with CSS</h3><p>The CSS we’ll use for the Gantt chart is included in the starter code. We’ve used <a href="https://github.com/vercel/styled-jsx">Styled JSX</a>, which comes with Next.js, to write scoped-styled components. There are some global styles in styles/globals.js. These global styles are added to our app in the Layout component in the components folder. The entire app is wrapped in this Layout component in the _app.js file, which is in the pages folder.</p><p>The &lt;style jsx&gt; tags in the components contain CSS that is scoped to the component. Styled JSX does this by making the class names unique. In the GanttChart component, there are some CSS variables for color, border radius, and cell height, which we’ll use for the Gantt chart.</p><h3>Utility functions, helpers, constants, and data</h3><p>The fetchWrapper.js file in the utils folder contains a fetch API wrapper function that we’ll use to make HTTP requests to our API endpoint. This wrapper function is from Kent C. Dodd’s article <a href="https://kentcdodds.com/blog/replace-axios-with-a-simple-custom-fetch-wrapper">Replace Axios with a simple custom fetch wrapper</a>. We’ll use this fetch wrapper function to fetch the example Gantt chart data, which is in the data.json file in the public folder.</p><p>The dateFunctions.js file in the helpers folder contains helper functions that we’ll use for date calculations and formatting. Finally, the constants.js file in the root folder contains a months array that we’ll use for creating the columns of the Gantt chart and for populating the select input elements for selecting the date range of our Gantt chart.</p><p>Now let’s start creating the Gantt chart component.</p><h3>Adding state</h3><p>First, we’ll add state to the GanttChart component. We’ll add state for the tasks, task durations, and the time range that will show on the Gantt chart. We’ll use blue horizontal bars across the cells to show task durations.</p><p>Import the useState and useEffect hooks in GanttChart.js:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86f4040c80bb18f34f27ea4ddf44a654/href">https://medium.com/media/86f4040c80bb18f34f27ea4ddf44a654/href</a></iframe><p>Add the following state variables and setters to the GanttChart() function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c398693be681ee165a0e6412df692877/href">https://medium.com/media/c398693be681ee165a0e6412df692877/href</a></iframe><p>We’ll get the tasks and taskDurations data from the data.json file by making a fetch request using the client fetch wrapper. Import the client function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d81a8692d5c6bedf91614678f7b50929/href">https://medium.com/media/d81a8692d5c6bedf91614678f7b50929/href</a></iframe><p>Add the following useEffect hook to fetch the data:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc49654eaa742b05e268928325ff4d5d/href">https://medium.com/media/dc49654eaa742b05e268928325ff4d5d/href</a></iframe><p>After the data is fetched, the tasks and taskDurations state will be set. You’ll be able to see the state in the <a href="https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en">React Developer Tools</a> “Components” tab.</p><figure><img alt="Gantt chart — state" src="https://cdn-images-1.medium.com/max/1024/1*yJMZy6qkRbzxLh0OT59KWw.png" /></figure><h3>Creating the Gantt chart component</h3><p>The Gantt chart component will be composed of seven components, which you’ll find in the components/GanttChart folder. In the Home page file index.js, located in the pages folder, we’ll import the main file GanttChart.js. There is also an AddButton component that is used in the AddTask and AddTaskDuration components.</p><figure><img alt="Gantt chart components" src="https://cdn-images-1.medium.com/max/1024/1*QeA-OBIDPRvQdSpR5krHtw.png" /></figure><p>Import the seven components in GanttChart.js:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/66b1e249a99c2bd4d07b2c8e2d79b0fd/href">https://medium.com/media/66b1e249a99c2bd4d07b2c8e2d79b0fd/href</a></iframe><p>Now add them in the &lt;div&gt; with an id of gantt-container:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c3072c61296763285f75bae0daa106c/href">https://medium.com/media/5c3072c61296763285f75bae0daa106c/href</a></iframe><p>The Grid and Settings components are wrappers that apply some CSS styles to their children. For each of the components, destructure the passed-in props. For example, in the Tasks component, destructure tasks, setTasks, and setTaskDurations as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb1756be4c47d280623ed515995bdc64/href">https://medium.com/media/fb1756be4c47d280623ed515995bdc64/href</a></iframe><p>As well as in the TimeTable component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4b297d906ab90fed33c7f254dffa53d/href">https://medium.com/media/b4b297d906ab90fed33c7f254dffa53d/href</a></iframe><p>Do the same for the AddTask, AddTaskDuration, and TimeRange components.</p><p>If you run your local server now, you should see the following basic skeleton of our app in your browser window:</p><figure><img alt="Gantt chart initial" src="https://cdn-images-1.medium.com/max/1024/1*kKyKRlsFmSF6VLJEitXpvw.png" /></figure><h3>Creating task rows</h3><p>The Tasks component currently renders three empty div rows. Below the last &lt;div className=”gantt-task-row”&gt;&lt;/div&gt; line, add the following code to create our task inputs:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b0e38e50f5cc631fde2caf7254e64f0/href">https://medium.com/media/2b0e38e50f5cc631fde2caf7254e64f0/href</a></iframe><p>We first check if tasks is not null, because Next.js does server-side rendering. The tasks state is added after the component is mounted.</p><p>We create an &lt;input&gt; element for each task with a value equal to the task name. There is a delete button for deleting the element. We’ll use the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/data-*">data attributes</a> to update the tasks state when a task is edited or deleted.</p><h3>Making tasks deletable</h3><p>Now let’s make the delete buttons work. First, add the following property to the delete button:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c362916c2e48bd30149ee3c852e3249f/href">https://medium.com/media/c362916c2e48bd30149ee3c852e3249f/href</a></iframe><p>Now add the following handleDelete function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8dd1d5b67a34be3d14767c1e2ad99acd/href">https://medium.com/media/8dd1d5b67a34be3d14767c1e2ad99acd/href</a></iframe><p>We pass in a function to setTaskDurations to get the previous value of the state from the function’s argument. We get the task id from the data attribute on the button. We then update the tasks state by filtering out the task by id from the tasks state passed in as a prop and then setting the tasks state using setTasks. We also update the tasksDurations state by removing any task durations associated with the deleted task and then updating the state. This causes the Tasks component to re-render, which passes in the new state.</p><p>Now if you click on the delete button, the task will be deleted.</p><h3>Making tasks editable</h3><p>The task inputs are not editable, let’s fix that. Add the following onChange property to the task &lt;input&gt;:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0612de25ba6f5d80ce6beb566d59089/href">https://medium.com/media/a0612de25ba6f5d80ce6beb566d59089/href</a></iframe><p>Now add the following onChange function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65c9c8432ddeb55768139d5ce3966251/href">https://medium.com/media/65c9c8432ddeb55768139d5ce3966251/href</a></iframe><p>We get the value of the input, and id for the task. We then create a new tasks state by filtering out the edited task, creating a new task object and then updating the tasks state. We also sort the tasks by id, the order in which they are created. When we add new tasks later in this tutorial, we’ll see that the given id is a number: the most recently created tasks have a higher number.</p><p>Now try editing the tasks in your development server. You’ll notice that the input loses focus after you add or remove a character from it. The tasks state is updated, as you can see in your React development tools. The input loses focus because the Tasks component is re-rendered each time the tasks state updates.</p><p>We’ll fix this using two refs that will allow us to focus the correct input on each re-render. Add the following ref objects:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40fd95df06b61f471d36789079c5093f/href">https://medium.com/media/40fd95df06b61f471d36789079c5093f/href</a></iframe><p>The inputRef will contain an array of our input elements. The indexRef will hold the index of the last input that has been changed. The ref values will persist after each re-render.</p><p>Add the following ref property to the task &lt;input&gt;:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25538495de66d9033586ed4cb08138f8/href">https://medium.com/media/25538495de66d9033586ed4cb08138f8/href</a></iframe><p>This will set the current value of the inputRef. The array will contain a ref to each input element.</p><p>In the onChange function, add the following line:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/773dc420b8e6ee55cd2bfcd4c7d74ef9/href">https://medium.com/media/773dc420b8e6ee55cd2bfcd4c7d74ef9/href</a></iframe><p>This will set the indexRef to the index of the last edited input.</p><p>Now we can use these two refs to focus the input that a user is editing. Add the following useEffect hook to the Tasks component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d93baeb8984ab9659d2c5214725dc0c0/href">https://medium.com/media/d93baeb8984ab9659d2c5214725dc0c0/href</a></iframe><p>This useEffect will run on each render. It will set focus on the input that was last edited. Now try editing the tasks in your development server. The input will maintain focus as you are editing the task.</p><h3>Creating the Gantt chart grid</h3><p>We’ll create the Gant chart grid in the TimeTable component. At the top of the TimeTable.js file, there are some objects, including ganttTimePeriod, that we’ll use for dynamic CSS styling. We’ll create the grid using similar code to the <a href="https://www.bryntum.com/blog/creating-a-gantt-chart-with-vanilla-javascript/">previous article</a>, which used vanilla JavaScript. We’ll create the grid row by row. We’ll add the task duration bars to the correct starting cell by checking the task duration’s task property and its start date.</p><p>There is some starter code for creating the rows. We’ll fill the monthRows, dayRows, and weekRows arrays with React elements for the Gantt chart grid and then render them.</p><p>Replace the imported modules with the following modules:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f41a8850d455384dcb2e48581ddf738/href">https://medium.com/media/1f41a8850d455384dcb2e48581ddf738/href</a></iframe><p>Above the component’s return, add the following for loop:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58b10a0f546df99b5cf0732072e460ef/href">https://medium.com/media/58b10a0f546df99b5cf0732072e460ef/href</a></iframe><p>This loops through the number of months in the time period range and creates month, week, and day rows. The value for numMonths is two. We will be able to change this value when we complete the TimeRange component’s code later in the tutorial. We use the month variable and the setMonth method to increment the month value on each loop. We use this value and the months array from our constants file to add styled React elements with the correct month name to the monthRows array.</p><p>We use a nested loop to create the dayRow and weekRow cells. We make use of JavaScript <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date">Date</a> methods, as well as the getDaysInMonth and getDayOfWeek functions from our dateFunctions file.</p><p>If you view your app now, you’ll see the year and month, day of the month, and day of the week rows. They’ll be positioned correctly once we add the date cells for each task.</p><figure><img alt="Gantt chart date rows" src="https://cdn-images-1.medium.com/max/1024/1*o98LiJTY7iPV4V9SmP0bbA.png" /></figure><p>Now let’s create the task row cells and add the task durations. Make sure the following functions are imported from dataFunctions.js:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38114f28f50ff57287a83b9d9e8af791/href">https://medium.com/media/38114f28f50ff57287a83b9d9e8af791/href</a></iframe><p>Add the following for loop below the one that you added:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51b0e1af4d2fc227cd8f904a29c735f3/href">https://medium.com/media/51b0e1af4d2fc227cd8f904a29c735f3/href</a></iframe><p>We loop through each month as we did in the first for loop that we added. We use the nested for loop to create the cells. The data-attributes data-task and data-date are added to each cell. We’ll use these when we add drag-and-drop functionality to the task durations. For each cell, we map over the taskDurations state and add a task duration &lt;div&gt; element as a child of the cell if the cell’s task id and start date matches the task duration task and start properties. The width of the task duration element is determined by calculating the duration of the task duration using the dayDiff function and then multiplying it by 100% of the cell width using CSS.</p><p>Now you’ll see the task rows and task durations in your app.</p><figure><img alt="Gantt chart task rows and task durations" src="https://cdn-images-1.medium.com/max/1024/1*8AQnWlKwcXp9wLl1hfrp5w.png" /></figure><h3>Making task durations deletable</h3><p>Now let’s make our task durations deletable by pressing the delete button when the task duration is in focus. Add the following property to the task duration element, which is the &lt;div&gt; that’s returned where the taskDurations are mapped over (taskDurations.map((el, i) =&gt; {):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c187788c5ee3a094035727ae0f799ca6/href">https://medium.com/media/c187788c5ee3a094035727ae0f799ca6/href</a></iframe><p>Now let’s create the deleteTaskDuration function below the two for loops:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90f9d02da177ea649746995689ff9a13/href">https://medium.com/media/90f9d02da177ea649746995689ff9a13/href</a></iframe><p>The <a href="https://reactjs.org/docs/events.html">React SyntheticEvent</a> and the task duration id are passed into the deleteTaskDuration function. If the “Delete” or “Backspace” key is pressed, a new state object is created by filtering out the deleted task from the taskDurations state, and the state is updated.</p><h3>Adding drag-and-drop functionality to task durations</h3><p>Let’s add drag-and-drop functionality to our task durations to change the position of the task duration elements on the grid. Add the following state and its setter:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35745caa856c904e39143486ff2b675e/href">https://medium.com/media/35745caa856c904e39143486ff2b675e/href</a></iframe><p>The taskDurationElDraggedId state will keep track of the task duration id that is currently being dragged. Now add the following function below the deleteTaskDuration function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/997f0d04eb82b5102ecd5a026b83eb8a/href">https://medium.com/media/997f0d04eb82b5102ecd5a026b83eb8a/href</a></iframe><p>This function will handle setting the taskDurationElDraggedId state.</p><p>Now change the returned task duration &lt;div&gt; element to the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47a1fe7564d1c942c28574ff4ab1171b/href">https://medium.com/media/47a1fe7564d1c942c28574ff4ab1171b/href</a></iframe><p>We set the draggable property of the task duration &lt;div&gt; element to true. Of course, we don’t need this property for our drag and drop to work, but it’s good for UX because it creates a “ghost” image of the task duration element attached to the mouse cursor as it’s dragged. We then call the handleDragStart function and pass in the task duration id as an argument when dragging of the task duration starts. We also made the opacity of the task duration decrease while dragging.</p><p>Also, while dragging, you’ll see the task duration id in your dev tools console.</p><p>Add the following property to the task row cell, which has a data-task property:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e193ce0884bf5117e362a0ff42e56e0/href">https://medium.com/media/8e193ce0884bf5117e362a0ff42e56e0/href</a></iframe><p>We add the <a href="https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/ondrop">onDrop</a> attribute to define the <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/drop_event">drop</a> event handler for each cell in the drag-and-drop zone of the grid, which is the task cells area. Dropping an element on a cell will trigger an onTaskDuration function call. Let’s define the onTaskDurationDrop function. Add the following lines below the handleDragStart function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/710bbca6631a1cf3def3689bd008cd13/href">https://medium.com/media/710bbca6631a1cf3def3689bd008cd13/href</a></iframe><p>We prevent a task duration from being added on top of another task duration by checking if the target cell has a draggable attribute. We then update the taskDuration state. We first find the task that was dragged and dropped, and remove it from a copy of the taskDurations state. We then create a new task duration and add it to the copied state. We use this copied and modified state to update the state.</p><p>If you now try to drag a task duration, you’ll see that the cursor will turn to the “not-allowed” icon. This is because dragging and dropping an element inside of another element is disabled by default. To remove this default behavior in our drag-and-drop zone, add the following property to the &lt;div&gt; element with an id of gantt-time-period-cell-container:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15ef441bc77bdde7229b41de241b601f/href">https://medium.com/media/15ef441bc77bdde7229b41de241b601f/href</a></iframe><p>Now that the drag-and-drop works, let’s get the “Add Task” form working.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1c3xc5-NawdYaPWA679rQw.gif" /></figure><h3>Making the “Add task” form functional</h3><p>In the AddTask component, the form has an input element with an onChange event handler that updates the local state variable task. Submitting the form will call the handleSubmit function. We need to complete this function by updating the tasks state using the passed-in prop setTasks.</p><p>Set the new tasks state by adding the following state setter above setTask(‘’):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/884217226aab4530faa2d262590fbd18/href">https://medium.com/media/884217226aab4530faa2d262590fbd18/href</a></iframe><p>We create a new task and add it to a copy of the state, newState, and then return it from setState to replace the state with the new state.</p><p>To determine the new task id, we use the reduce method to find the largest current task id, and then add one to it to create the id for the new task. The task id values are numbers that represent the order in which they were created. The tasks are sorted by their id.</p><p>You’ll now be able to add tasks to your Gantt chart. When you add a task, the Gantt Chart is re-rendered, displaying the new tasks state.</p><h3>Making the “Add task duration” form functional</h3><p>The AddTaskDuration component is partly created for you, like the AddTask component was. We need to loop through the passed-in tasks state and populate the “Which tasks” &lt;select&gt; input. We also need to update the taskDuration state using the passed in setTaskDurations state setter.</p><p>The form has three inputs: a &lt;select&gt; input for selecting the task that the task duration is for, and two date inputs for selecting the start and end date of the task duration. The form state is managed using the three local state variables, task, startDate, and endDate, as well as their state setters. The onChange function handles updating the local state when an input value is changed.</p><p>First, let’s populate the tasks &lt;select&gt; input with &lt;option&gt; elements for each task. Add the following code inside of the &lt;select&gt; input with an id of select-task:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4c329f9820ae1751d1b6be5befe1cdc/href">https://medium.com/media/c4c329f9820ae1751d1b6be5befe1cdc/href</a></iframe><p>Now you’ll see that the &lt;select&gt; menu is populated with all the task names. If you add a task, you’ll see that it’s added to the &lt;select&gt; menu as the GanttChart component re-renders.</p><p>To get the handleSubmit function to work, add the following lines to it, below e.preventDefault():</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b94f5e4eea1ff820d8efa317de398bd1/href">https://medium.com/media/b94f5e4eea1ff820d8efa317de398bd1/href</a></iframe><p>If a task has not been selected, we return. We then create a new task duration using the local state and a time stamp for the `id`. We then set the `taskDurations` state using `setTaskDurations` by returning a new array from the passed-in function.</p><p>You’ll now be able to add new task durations to your Gantt chart.</p><h3>Making the “Tracker period” functional</h3><p>To complete the code for the TimeRange component, we need to give each &lt;select&gt; element the correct value using the passed-in timeRange state. We then need to update this state in the onChange handler function.</p><p>Replace the value props of the four &lt;select&gt; elements with the following value props:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15a88e430d055c6ff4788dadd261720a/href">https://medium.com/media/15a88e430d055c6ff4788dadd261720a/href</a></iframe><p>Now add the following lines to the onChange function, below the line const { value, id } = e.target;:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69f679dfd779759030178108d635713d/href">https://medium.com/media/69f679dfd779759030178108d635713d/href</a></iframe><p>When the value of one of the &lt;select&gt; inputs is changed, we update the timeRange state. This causes the GanttChart component to re-render, which will show the updated time range.</p><p>We’ve completed our basic Gantt chart, but the process was a little tedious and possibly not bug free. Now let’s create a Gantt chart using our <a href="https://bryntum.com/examples/gantt">Bryntum Gantt</a> component for comparison.</p><h3>Using Bryntum Gantt with Next.js</h3><p>To install Bryntum Gantt with npm you just need to install two libraries with zero external dependencies. If you are unfamiliar with Bryntum products, you can follow the guide <a href="https://www.bryntum.com/docs/gantt/guide/Gantt/npm-repository">here</a>.</p><p>Let’s import the Bryntum Gantt component. In the components folder, create a Gantt.js file and add the following lines:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5bf1eb86b88ab02d1357874dacc9c4c/href">https://medium.com/media/e5bf1eb86b88ab02d1357874dacc9c4c/href</a></iframe><p>We’ll use the imported BryntumGantt component. We’ll pass in a config file as props to determine how the Gantt chart looks and where it gets data from. You can also pass in a ref if needed.</p><p>We need to import the BryntumGantt component <a href="https://nextjs.org/docs/advanced-features/dynamic-import">dynamically</a>. Create another component called GanttInstance.js and add the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce9d091d6d346a23d0d5c53d49d5694d/href">https://medium.com/media/ce9d091d6d346a23d0d5c53d49d5694d/href</a></iframe><p>In the project’s root folder, create a ganttConfig.js file and add the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/66edfc92dda2b70b7b389aa563b144b1/href">https://medium.com/media/66edfc92dda2b70b7b389aa563b144b1/href</a></iframe><p>We pass in the configuration from ganttConfig.js to the Gantt component. This includes the columns property to create the Gantt chart columns for the tasks. You can learn more about the config options in the <a href="https://bryntum.com/docs/gantt/api/Gantt/view/Gantt#configuring-data-for-gantt">Bryntum docs</a>.</p><p>We configure the project with the <a href="https://www.bryntum.com/docs/gantt/guide/Gantt/integration/react/data-binding#using-project-transport">transport</a> property to populate the Gantt chart’s data stores. We’ve configured the url to load data using the load property. The url data source is a JSON file in the public folder of the starter repository. You can also configure the transport to sync data changes to a specific url. For more information, you can read the following guide in our docs: <a href="https://www.bryntum.com/docs/gantt/guide/Gantt/integration/react/data-binding">Binding Bryntum Gantt data</a>.</p><p>We dynamically import the Gantt component with ssr set to false. While the component is loading, we display a loading component that returns a &lt;p&gt; tag with the message “Loading…”.</p><p>In order for the Gantt chart’s data population to work, we need to turn off [strict mode](<a href="https://reactjs.org/docs/strict-mode.html">https://reactjs.org/docs/strict-mode.html</a>). Set reactStrictMode to false in the next.config.js file, which is in the project’s root folder:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aacdbca74930002a94671154c04a03e3/href">https://medium.com/media/aacdbca74930002a94671154c04a03e3/href</a></iframe><p>Let’s create a page to view our Bryntum Gantt chart. In the pages folder, create a file named bryntum.js and add the following lines to it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c395fc9a18c1a8b5543ad32e37cd5eb/href">https://medium.com/media/1c395fc9a18c1a8b5543ad32e37cd5eb/href</a></iframe><p>We import our GanttInstance component and the CSS for the Bryntum Gantt Stockholm theme, which is one of five available themes. You can see a demo showing the different themes <a href="https://bryntum.com/examples/gantt/theme/">here</a>. You can also create custom themes. In this demo, you can also learn about the different components of the Gantt chart by clicking on the “Learn” button in the top right corner.</p><figure><img alt="Bryntum Gantt chart themes" src="https://cdn-images-1.medium.com/max/1024/1*DWlGdFklh59ZD1INb7zIwg.png" /></figure><p>The GanttInstance component is wrapped in a &lt;div&gt; with a class of container. We give it a height of 100vh so that the Gantt chart fills the whole screen.</p><p>In your app, go to the bryntum route by going to the following url: <a href="http://localhost:3000/bryntum">http://localhost:3000/bryntum</a>. You’ll now see the Bryntum Gantt chart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YC9dWn6S6ZlBvZrdtptDOg@2x.png" /></figure><p>This basic example of the Bryntum Gantt component has more features by default than the Gantt chart that we created. The features include:</p><ul><li>Collapsible task groups.</li><li>Drag-and-drop re-ordering of tasks.</li><li>Add, edit, copy, and delete tasks. Right-click on a task to see a pop-up menu with these actions.</li><li>Draggable task durations.</li><li>Re-sizeable task durations. Hover your mouse over the left or right side of a task duration, which is green, until the cursor changes to a resize icon. Then click and hold down while you move your mouse left or right.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*nsQnLA0PXxfkrND4ng0AxA@2x.png" /></figure><p>Try out some of these features in your app.</p><h3>Comparing the vanilla JS, React, and Bryntum Gantt charts</h3><p>Let’s compare the Gantt chart that we created with the basic example of the Bryntum Gantt chart, as well as the vanilla JavaScript one that we created in a <a href="https://www.bryntum.com/blog/creating-a-gantt-chart-with-vanilla-javascript/">previous article</a>.</p><p>Breaking the React Gantt chart into different components, organizing code, and managing state was easier than when vanilla JavaScript was used. React manages state declaratively, which makes managing it easier. The vanilla JavaScript Gantt chart required a lot of direct DOM manipulation, selecting DOM elements and adding events to them. The code of the vanilla JavaScript Gantt chart and React Gantt chart are quite similar, however because we used Next.js, we had to take SSR into account.</p><p>The Bryntum Gantt chart was easy to set up, it has a very customizable API that you can learn about in the <a href="https://www.bryntum.com/docs/gantt/">API docs</a>. You can see all the available features <a href="https://www.bryntum.com/products/gantt/features/">here</a> and view an advanced demo of a React Gantt chart <a href="https://www.bryntum.com/examples/gantt/frameworks/react/javascript/advanced/build/">here</a>. The advanced demo includes features such as highlighting critical paths, theme selection, and undoing or redoing actions.</p><p>The Bryntum Gantt chart is built with pure JavaScript/ES6+ and it uses a very fast rendering engine. Its performance is great even with large datasets. You can test this yourself: Return to your local development server and set the Tracker Period in the custom-built Gantt to its maximum range and add a new task. You’ll notice that it takes a couple of seconds for the new task to be added. This is because there are many cells to render. Try this with the <a href="http://preview.ritza.co/bryntum/gantt/">live example</a> of the vanilla JavaScript Gantt from the previous article as well. You’ll notice the same thing.</p><p>Now change the date range of the project in the chart that you created with the Bryntum Gantt component. Make the date range 1000 years and then add a task. There is no noticeable difference in performance.</p><h3>Next steps</h3><p>There are many ways you can add to or improve the Gantt chart component as described in the “Next Steps” section of our <a href="https://www.bryntum.com/blog/creating-a-gantt-chart-with-vanilla-javascript/">previous article</a> where we used vanilla JavaScript to create a Gantt chart. Unlike the vanilla JavaScript Gantt chart, you don’t need to worry about sanitizing the task and task duration data with React.</p><p>You can improve the Gantt chart by adding input validation. State management can also be improved by preventing unnecessary re-renders. The TimeTable component renders the table using many nested loops. Minimizing the number of nested loops would improve performance.</p><h3>Build or buy?</h3><p>This article gives you a starting point for building your own React Gantt chart using Next.js. If you’re instead looking to buy an off-the-shelf, battle-tested solution that just works, take a look at some examples of our <a href="https://bryntum.com/examples/gantt">Bryntum Gantt</a>. With the Bryntum Gantt component, you can:</p><ul><li>Schedule tasks using dependencies and constraints.</li><li>Leverage calendars for projects, tasks, and resources.</li><li>Use recurrent and fixed time intervals.</li><li>Customize rendering and styling.</li><li>Customize user experience through many different column types and task editors.</li><li>Deal with extensive datasets and performance tuning.</li></ul><p>We also have a <a href="https://www.bryntum.com/forum/">support forum</a> and offer <a href="https://www.bryntum.com/services/">professional services</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc080ad8b938" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bryntum/creating-a-gantt-chart-with-react-using-next-js-fc080ad8b938">Creating a Gantt chart with React using Next.js</a> was originally published in <a href="https://medium.com/bryntum">Bryntum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making an interactive CSS avatar editor with zero lines of JS]]></title>
            <link>https://medium.com/bryntum/making-an-interactive-css-avatar-editor-with-zero-lines-of-js-c67d8121e644?source=rss----32ca805267d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/c67d8121e644</guid>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Johan Isaksson]]></dc:creator>
            <pubDate>Thu, 11 Aug 2022 14:19:48 GMT</pubDate>
            <atom:updated>2022-08-11T14:19:48.112Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PVCW-ei-OwSjCZFbCjAkZA.png" /></figure><p>This post explores CSS interactivity by showing some techniques that can be used to create a simple avatar editor, without any JavaScript. It was amusing to implement and I hope it will be equally amusing to read &amp; try. With that said, I would not recommend anyone actually using this in production. 😊</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fjohan-bryntum%2Fembed%2Fpreview%2FBarYdmq%3Fdefault-tabs%3Dcss%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DBarYdmq&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fjohan-bryntum%2Fpen%2FBarYdmq&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6c7f1cc0700b6542dd9d56913e51df5/href">https://medium.com/media/c6c7f1cc0700b6542dd9d56913e51df5/href</a></iframe><h3>Interactivity using CSS</h3><p>The CSS <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:checked">:checked</a> pseudo-class selector can be used to add a basic level of interactivity to a page without using JavaScript. It is a special selector in that it is toggled on and off as a user toggles a checkbox or radio button. For example, the following snippet makes a checked checkbox twice as large as an unchecked:</p><pre>input:checked { transform : scale(2); }</pre><p>Which looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*HeT4aCF-Gqz7-HDk829Msg.png" /><figcaption>Checked box is twice as large as the others</figcaption></figure><p>By linking a label to the checkbox or radio button (using id and for), you can also click on the label to toggle the checkbox:</p><pre>&lt;input type=&quot;checkbox&quot; id=&quot;box&quot; /&gt;<br>&lt;label for=&quot;box&quot;&gt;Click label to toggle&lt;/label&gt;</pre><p>By using <a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Combinators">CSS sibling combinators</a> you can affect the label when the checkbox is toggled:</p><pre>input:checked + label { background : orangered; }</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fjohan-bryntum%2Fembed%2Fpreview%2FQWmVEVb%3Fdefault-tabs%3Dcss%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DQWmVEVb&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fjohan-bryntum%2Fpen%2FQWmVEVb&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/8fe013e9a879103cdbf054cedd790889/href">https://medium.com/media/8fe013e9a879103cdbf054cedd790889/href</a></iframe><p>If you then hide the checkbox, it can still be toggled using the label. Which opens up for interesting possibilities, like in these CSS only examples found on CodePen:</p><ul><li>Tabs, <a href="https://codepen.io/MPDoctor/pen/mpJdYe">https://codepen.io/MPDoctor/pen/mpJdYe</a></li><li>Hamburger menu, <a href="https://codepen.io/erikterwan/pen/EVzeRP">https://codepen.io/erikterwan/pen/EVzeRP</a></li><li>Block stacking game, <a href="https://codepen.io/finnhvman/pen/xJRMJp">https://codepen.io/finnhvman/pen/xJRMJp</a></li></ul><h3>Building a CSS only range control</h3><p>Each segment of the range will be represented by a radio button and a label. The label will be styled to look like a segment of a range control. Below is the HTML defining a range control with 4 segments:</p><pre>&lt;div class=&quot;range&quot;&gt;<br>    &lt;input type=&quot;radio&quot; id=&quot;range4&quot; name=&quot;range&quot;&gt;<br>    &lt;label for=&quot;range4&quot;&gt;&lt;/label&gt;<br>    &lt;input type=&quot;radio&quot; id=&quot;range3&quot; name=&quot;range&quot;&gt;<br>    &lt;label for=&quot;range3&quot;&gt;&lt;/label&gt;<br>    &lt;input type=&quot;radio&quot; id=&quot;range2&quot; name=&quot;range&quot; checked&gt;<br>    &lt;label for=&quot;range2&quot;&gt;&lt;/label&gt;<br>    &lt;input type=&quot;radio&quot; id=&quot;range1&quot; name=&quot;range&quot;&gt;<br>    &lt;label for=&quot;range1&quot;&gt;&lt;/label&gt;<br>&lt;/div&gt;</pre><p>Without styles we’re not fooling anyone:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/120/1*A0Eg7N0RNkTgtpAectAeYA.png" /><figcaption>Un-styled CSS range control, what a beauty!</figcaption></figure><p>By adding a little CSS, we can make it look like the track of a range control:</p><pre>.range {<br>    display : flex;<br>}<br><br>/* Hide the radio buttons */<br>.range input {<br>    display : none; <br>}<br><br>/* Style labels to look like a solid range control track */<br>.range label {<br>    width        : 16px;<br>    height       : 6px;<br>    background   : #efefef;<br>    border-block : 1px solid #b2b2b2;<br>    display      : flex;<br>    align-items  : center;<br>}<br><br>.range label:first-of-type {<br>    border-radius       : 6px 0 0 6px;<br>    border-inline-start : 1px solid #b2b2b2;<br>}<br><br>.range label:last-of-type {<br>    border-radius     : 0 6px 6px 0;<br>    border-inline-end : 1px solid #b2b2b2;<br>}</pre><p>Resulting in this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/168/1*K6M7GxQx3Sv6C-MNjmTpGA.png" /><figcaption>Range control, minus thumb</figcaption></figure><p>To highlight the current value, we leverage :checked and style a pseudo-element for the label to act as the thumb:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/152/1*xFg68nQ8gJvy3_lc0zGCjA.png" /><figcaption>Range control, with 👍</figcaption></figure><p>Now on to the tricky part, we also want to highlight the part of the track before the thumb. Problem is, there is no CSS combinator (not yet anyway) to target previous siblings. By reversing the element order in DOM we can target what visually appears to be previous siblings with the ~ combinator 😵‍💫</p><pre>.range { <br>    /* Reverse element order */ <br>    flex-direction : row-reverse; <br>    /* Move them back to the left */ <br>    justify-content : flex-end; <br>}</pre><p>A mess:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/148/1*SGrB12lpWA_i-oqX7iAgwg.png" /><figcaption>What? 😳</figcaption></figure><p>First segment is now last and vice versa, you also have to switch places of the :first-of-type and :last-of-type selectors for appearance to be correct again:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/152/1*xFg68nQ8gJvy3_lc0zGCjA.png" /><figcaption>Pew 😮‍💨</figcaption></figure><p>And lastly we add the track highlight (made possible with the reversal above):</p><pre>.range :checked ~ label { <br>    background : #0075ff;<br>    border-color : #4b76bb; <br>}</pre><p>Looks like a range control!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fjohan-bryntum%2Fembed%2Fpreview%2FPoRdGKP%3Fdefault-tabs%3Dcss%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DPoRdGKP&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fjohan-bryntum%2Fpen%2FPoRdGKP&amp;image=https%3A%2F%2Fshots.codepen.io%2Fjohan-bryntum%2Fpen%2FPoRdGKP-512.jpg%3Fversion%3D1660224522&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/40142af8e8ec264e42d7d140bcc26e9c/href">https://medium.com/media/40142af8e8ec264e42d7d140bcc26e9c/href</a></iframe><h3>Using the range control for interactivity</h3><p>While the range control above looks nice and is interactive, we should use it to manipulate something else 🤔. We can (currently) only affect sibling elements, by once again using the ~ combinator. Therefor, we have to put another element into the outer .range element:</p><pre>&lt;div class=&quot;range&quot;&gt;<br>    &lt;!-- Existing range markup --&gt;<br>    <br>    &lt;div class=&quot;avatar&quot;&gt;&lt;/div&gt;<br>&lt;/div&gt;</pre><p>And use some more CSS magic, here to scale the avatar depending on range value (using CSS variables):</p><pre>/* Represent the leftmost value, since we reversed the elements */<br>:nth-of-type(4):checked ~ .avatar {<br>    --avatar-size : 0.5;<br>}<br><br>:nth-of-type(3):checked ~ .avatar {<br>    --avatar-size : 0.75;<br>}<br><br>:nth-of-type(2):checked ~ .avatar {<br>    --avatar-size : 1;<br>}<br><br>/* Rightmost value */<br>:nth-of-type(1):checked ~ .avatar {<br>    --avatar-size : 1.25;<br>}<br><br>.avatar {<br>    /* Lots of CSS here to make the avatar look like a dog */<br>    <br>    transform : scale(var(--avatar-size));<br>}</pre><p>Try it out:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fjohan-bryntum%2Fembed%2Fpreview%2FzYWJKWJ%3Fdefault-tabs%3Dcss%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DzYWJKWJ&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fjohan-bryntum%2Fpen%2FzYWJKWJ&amp;image=https%3A%2F%2Fshots.codepen.io%2Fjohan-bryntum%2Fpen%2FzYWJKWJ-512.jpg%3Fversion%3D1660225142&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f701f0ea752e3d0389257a7d2560564/href">https://medium.com/media/4f701f0ea752e3d0389257a7d2560564/href</a></iframe><p><strong>That’s it! </strong>🎉 By using the techniques in the post it is possible to create the full avatar editor shown at top, be sure to check it out over at <a href="https://codepen.io/johan-bryntum/pen/BarYdmq">CodePen</a>. If you’re already using similar tricks in your application, we would love to hear about it.</p><p>PS. In a not too distant future, we will be able to use the :has() selector to affect an element that i️s not a direct sibling (we could also avoid reversing elements using it). Stay tuned for a future update using it ⭐</p><p><em>Originally published at </em><a href="https://www.bryntum.com/blog/making-an-interactive-avatar-editor-with-zero-lines-of-js/"><em>https://www.bryntum.com</em></a><em> on August 11, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c67d8121e644" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bryntum/making-an-interactive-css-avatar-editor-with-zero-lines-of-js-c67d8121e644">Making an interactive CSS avatar editor with zero lines of JS</a> was originally published in <a href="https://medium.com/bryntum">Bryntum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s new in 5.1.0 — Bryntum]]></title>
            <link>https://medium.com/bryntum/whats-new-in-5-1-0-bryntum-f3888dd1c28a?source=rss----32ca805267d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/f3888dd1c28a</guid>
            <category><![CDATA[web-components]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ux]]></category>
            <dc:creator><![CDATA[Mats Bryntse]]></dc:creator>
            <pubDate>Fri, 22 Jul 2022 07:10:26 GMT</pubDate>
            <atom:updated>2022-07-22T07:10:08.706Z</atom:updated>
            <content:encoded><![CDATA[<h3>What’s new in Bryntum 5.1.0</h3><p>We are super happy to announce the new <strong>5.1</strong> release of our Bryntum web component suite. In this update, you will find a new Row Expander feature, improved nested events support, and much more. We also spent a lot of time improving our documentation and onboarding.</p><h3>Onboarding</h3><p>For the past 5 years or so we have focused on catching up with the functionality of our old product line. Each product comes with a huge API, making them highly customizable, and they ship with a lot of demos to show off the functionality.</p><p>Based on feedback from our customer base, all this can be a bit overwhelming. We are now focusing on making it easier to use the products by investing in the onboarding process.</p><p>These are some of the goals we are working towards over the coming releases:</p><ul><li>Improved documentation, especially the Getting Started parts</li><li>More demos available for the major frameworks (React, Vue &amp; Angular)</li><li>Code viewer for the framework demos</li><li>Code snippets in docs for each major framework</li><li>Improved typings to help TypeScript users</li></ul><p>Considering that we have around 300 different demos in plain JavaScript and some 2000 snippets it won’t happen overnight, but the work has begun.</p><p>With this release we have reorganized the docs a bit and added content to make it easier to get started with the major frameworks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6L4ohWpcd7L6GSZk.png" /></figure><p>We have also ported 10+ vanilla JS demos to each framework:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f6cHksLKorEYhTzH.png" /></figure><p>And added “Create React App” templates for all products to simplify getting started with React. Available in our npm repo:</p><p>Finally, this release comes with improved typings for configs and properties that accept a set of strings to now list available options. For example:</p><pre>// Previously <br>type TextFieldConfig = { textAlign: string } </pre><pre>// Now <br>type TextFieldConfig = { textAlign: &#39;left&#39;|&#39;center&#39;|&#39;right&#39;|&#39;start&#39;|&#39;end&#39; }</pre><h3>Nesting events in Scheduler Pro</h3><p>Scheduler Pro now supports nesting events (one level deep) by consuming a tree store and enabling the new <a href="https://bryntum.com/docs/scheduler-pro/api/SchedulerPro/feature/NestedEvents">NestedEvents</a> feature. The nested events are draggable and resizable the same way as main events, and they can be dragged into, out of and between parent events (this behaviour is configurable).</p><p>The feature comes with two new demos, and the previously existing demo was rewritten to take advantage of the new feature:</p><figure><a href="https://bryntum.com/examples/scheduler-pro/nested-events-configuration"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Y3KWTWGRWpVboKLOvp_MA.png" /></a></figure><figure><a href="https://bryntum.com/examples/scheduler-pro/nested-events-drag-from-grid"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ckPpBx3n7jrfGir3SL9IA.png" /></a></figure><figure><a href="https://bryntum.com/examples/scheduler-pro/nested-events"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s8DAt8700QpbiOeKA_6nMQ.png" /></a></figure><h3>Dependencies feature improvements</h3><p>The dependencies feature got a big overhaul in this version, enabling the following (while at the same time removing 1000+ lines of code):</p><ul><li>Dependencies in vertical mode in Scheduler</li><li>Live redrawing of dependencies during transitions, drag and resize operations</li><li>A <a href="https://bryntum.com/docs/scheduler/api/Scheduler/feature/Dependencies#config-renderer">renderer</a> config, allowing apps to affect the outputted SVG per dependency</li><li>Rounded “corners” by configuring a <a href="https://bryntum.com/docs/scheduler/api/Scheduler/feature/Dependencies#config-radius">radius</a></li><li>Custom arrow heads</li></ul><p>The existing dependencies demo was updated to showcase the new functionality and we added a new demo for vertical mode.</p><figure><a href="https://bryntum.com/examples/scheduler/vertical-dependencies"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aeuVlMrLLY5tuswK1hGG6A.png" /></a></figure><h3>Row expander in Grid</h3><p>Grid has a much requested new <a href="https://www.bryntum.com/docs/grid/api/Grid/feature/RowExpander">RowExpander</a> feature that lets you expand and collapse rows, rendering any custom markup into the expanded part. Try it out in this new demo:</p><figure><a href="https://bryntum.com/examples/grid/rowexpander"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VdUIn9uOLhuMwy0u.png" /></a></figure><h3>Angular components now use ES module bundle</h3><p>The Angular wrapper and accompanying demos now use the ES module bundle instead of the legacy UMD bundle. Aside from being a more modern approach, the bundle is slightly smaller and more performant. If you are using our Angular wrapper, you need to adjust your imports accordingly:</p><pre>// 4.x imports from the umd bundle <br>// 5.1 imports from the module bundle (which is the default bundle for the package)</pre><pre>import { TaskModel } from &#39;@bryntum/gantt/gantt.umd.js&#39;; <br>import { TaskModel } from &#39;@bryntum/gantt&#39;;</pre><p>The Vue and React wrappers already use the ES module bundle. Please note that the UMD bundle will still be available but not used by default.</p><h3>More news</h3><p>The release contains even more new features and improvements, such as:</p><ul><li>Most keyboard shortcuts are now <a href="https://bryntum.com/docs/grid/api/Grid/view/Grid#keyboard-shortcuts">configurable</a> using the keyMap config</li><li>Scheduler’s vertical mode now supports <a href="https://bryntum.com/examples/scheduler/vertical-resource-widths">variable resource column widths</a></li></ul><p>For full details about this release, please see the change logs, What’s New guides and upgrade guides of each product.</p><h3>Summing up</h3><p>Version 5.1 brings some really nice new features and demos, almost exclusively based on the feedback received from our customers and community. We hope you will enjoy this release and please keep your feedback coming. Is there a specific feature you would like us to add next?</p><p><a href="https://bryntum.com/download">Download 5.1 Free Trial</a></p><ul><li><a href="https://www.bryntum.com/products/grid">Grid product page</a></li><li><a href="https://www.bryntum.com/products/scheduler">Scheduler product page</a></li><li><a href="https://www.bryntum.com/products/scheduler-pro">Scheduler Pro product page</a></li><li><a href="https://www.bryntum.com/products/gantt">Gantt product page</a></li><li><a href="https://www.bryntum.com/products/calendar">Calendar product page</a></li><li><a href="https://www.bryntum.com/products/taskboard">TaskBoard product page</a></li><li><a href="https://www.bryntum.com/docs">Docs</a></li><li><a href="https://www.bryntum.com/examples">Examples</a></li></ul><p><em>Originally published at </em><a href="https://www.bryntum.com/blog/whats-new-5_1_0/"><em>https://www.bryntum.com</em></a><em> on July 21, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3888dd1c28a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bryntum/whats-new-in-5-1-0-bryntum-f3888dd1c28a">What’s new in 5.1.0 — Bryntum</a> was originally published in <a href="https://medium.com/bryntum">Bryntum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Gantt chart with vanilla JavaScript]]></title>
            <link>https://medium.com/bryntum/creating-a-gantt-chart-with-vanilla-javascript-bd1612ab5472?source=rss----32ca805267d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/bd1612ab5472</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[web-components]]></category>
            <category><![CDATA[gantt-chart]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ritza]]></dc:creator>
            <pubDate>Wed, 29 Jun 2022 12:55:33 GMT</pubDate>
            <atom:updated>2022-08-19T15:38:43.889Z</atom:updated>
            <content:encoded><![CDATA[<p>by <a href="https://www.bryntum.com/blog/author/alex/">Alex L</a></p><p>A Gantt chart is a really handy project management tool for coordinating complex schedules for large teams or multiple teams. While many companies use Excel to build Gantt charts, using a Gantt chart that is JavaScript-based has a couple of advantages over spreadsheets, for example, you can:</p><ul><li>Easily integrate your chart into existing project management dashboards.</li><li>Share your chart online.</li><li>Customize your chart to suit your needs.</li></ul><p>Gantt charts are surprisingly complex, so if you’re looking to build your own for production use, this guide will only show you the first steps. If you instead prefer to buy a battle-tested off-the-shelf version, take a look at our commercial <a href="https://www.bryntum.com/examples/gantt">Bryntum Gantt Chart</a>.</p><p>Let’s take a look at how you can make a basic drag-and-drop Gantt chart component using vanilla JavaScript. You can find all the code used below in <a href="https://github.com/bryntum/gantt-chart-javascript-tutorial">our GitHub repository</a>.</p><p>The basic Gantt chart we will create will have the following features:</p><ul><li>The user can select the planning time period by selecting a start date and an end date.</li><li>We’ll be able to add, delete, and edit tasks.</li><li>Task durations can be added and deleted, and we’ll be able to edit them using drag and drop.</li></ul><p>You can see a live example of the final Gantt chart <a href="http://preview.ritza.co/bryntum/gantt/">here</a>. Once you’re done, you’ll have a Gantt chart that looks like the one shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7TnzSFkyoqmY6Ut0.png" /></figure><h3>Getting started</h3><p>We’ll create our Gantt chart using only HTML, CSS and JavaScript.</p><p>The CSS will be defined in JavaScript files. We will use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules">JavaScript modules</a> to split the code into separate modules that can be imported and exported, so we’ll need a local HTTP server to run the code. We need to do this because JavaScript modules follow the <a href="https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy">same-origin policy</a>, which means that you cannot import modules from your file system by default. To get a local server with live reload, you can install the npm <a href="https://www.npmjs.com/package/live-server">Live Server</a> package. If you are using VS Code, you can install the <a href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer">Live Server</a> extension.</p><p>If you want to do this tutorial in the browser with minimal setup, you can make use of Replit, which is an online integrated development environment (IDE). You can check their documentation for <a href="https://docs.replit.com/tutorials/introduction-to-the-repl-it-ide">how to create a project</a>.</p><p>Let’s get an overview of how the app will be structured and create the basic app and the building blocks of our component.</p><h3>Folder structure</h3><p>Everything that can be exported using the export statement is considered a component. The index.html file will only import a single JavaScript file, script.js, which is a module. This will be the single entry point to our application. The Gantt chart component is imported into script.js.</p><p>We will break the Gantt component up into four separate components:</p><ul><li>The main module, ganttChart.js,</li><li>A module for the HTML, htmlContent.js,</li><li>A module for the CSS, style.js, and</li><li>A module for some utility functions, utils.js.</li></ul><p>A utility function is a generic function that performs a task that we could reuse in another project. We will create utility functions for date calculations and date formatting.</p><p>Create the following files and folders:</p><pre>|__ index.html<br>|__ script.js<br>|__ components <br>    |__ ganttChart<br>        |__ ganttChart.js<br>        |__ htmlContent.js<br>        |__ style.js<br>        |__ utils.js</pre><h3>Basic app structure</h3><p>Before we make the Gantt chart component, let’s set up the app that will render the Gantt chart. Add the following lines to the index.html file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f91176d463187db05ab19f5db535159/href">https://medium.com/media/8f91176d463187db05ab19f5db535159/href</a></iframe><p>The type=module attribute of the script.js file that we embed into our HTML document allows us to use module features in our script. In the &lt;body&gt; tag there is a single &lt;div&gt; with a role of “gantt-chart”. We use this to identify the HTML element that will be used to create our Gantt chart component.</p><p>Now add the following lines to the script.js file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0092d1ef53db2a9488fa67d2b8ad99ca/href">https://medium.com/media/0092d1ef53db2a9488fa67d2b8ad99ca/href</a></iframe><p>We import GanttChart, which will be the constructor function that creates our Gantt chart. Once the HTML content is loaded and parsed, we create our Gantt chart. You can create multiple instances of the Gantt chart if you need to.</p><p>We hard code the tasks and taskDurations data objects for the Gantt chart. You could get this data from your backend using an HTTP request. The taskDurations indicate the duration of a task. They have a task property, which specifies the task it is associated with, as indicated by the task id property. They also have start and end date properties, which indicate the task duration. These are <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date">JavaScript Date</a> objects.</p><p>For each HTML element on our page that has a role of “gantt-chart”, we create a Gantt chart using the GanttChart <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/Function">constructor function</a>. We pass in the ganttChart DOM element object, as well as the task and task duration data. This function creates the content of the Gantt chart component.</p><h3>HTML structure</h3><p>Now let’s describe the Gantt chart component. The following diagram describes the Gantt chart layout. The numbered blocks represent the &lt;div&gt; containers for each part of the Gantt chart. They each have a unique id.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kNrfnBfBTyH4IETzxLRnVQ.png" /></figure><p>Let’s add the HTML needed for our Gantt Chart component. Add the following lines to the htmlContent.js file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df3d7d272138a96f05ac1bbc44d73e9a/href">https://medium.com/media/df3d7d272138a96f05ac1bbc44d73e9a/href</a></iframe><p>We import our CSS styles as a string from style.js, which we will define in the next section. We create an HTML string and store it in the content variable. We will go through the specifics of the HTML and CSS as we go through the tutorial. We convert the HTML string into DOM nodes by creating a <a href="https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment">DocumentFragment</a> that is stored in the contentFragment variable. This document fragment is made up of DOM nodes, and is separate from the document DOM tree. It will not be displayed on the page until we add it to the document DOM. The createHtmlContentFragment function returns the contentFragment variable. Later, we will add this document fragment as a child to the Gantt chart DOM element to put it on the page.</p><h3>Adding styling with CSS</h3><p>Now let’s add the basic styling for our Gantt chart component. Add the following lines to the styles.js file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f73775cadf4573b2595cf7f5f5cb56a9/href">https://medium.com/media/f73775cadf4573b2595cf7f5f5cb56a9/href</a></iframe><p>We export a cssStyles function from this module. It returns a CSS string that we import and add to the HTML string in htmlContent.js. The variable ROW_HEIGHT allows us to easily change the height of the rows in the Gantt Chart.</p><h3>Adding utility functions</h3><p>Next, we’ll add some utility functions for our Gantt chart component. Add the following lines to the utils.js file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8d8335b6278ef31cc78656cfca91443/href">https://medium.com/media/b8d8335b6278ef31cc78656cfca91443/href</a></iframe><p>These functions will be used for date calculations and date formatting. We will go through the specifics of the functions as we use them in the tutorial.</p><h3>Creating the Gantt chart component</h3><p>Now that we have the basic structure of our app set up, we can start creating the Gantt chart. We will only work in the ganttChart.js file from now on. Add the following to the ganttChart.js file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/453cb3e2662ae5b66155b10034b08c8e/href">https://medium.com/media/453cb3e2662ae5b66155b10034b08c8e/href</a></iframe><p>We import all the functions we need from the other modules. The GanttChart constructor function takes in the Gantt chart DOM element, tasks, and task durations as arguments. We also create some variables that we will use later, including a contentFragment variable that is the document fragment of our HTML content from htmlContent.js. We then append this to the ganttChartElement so that it is added to the document DOM.</p><p>Now let’s add the month and year options for our “From” and “To” &lt;select&gt; elements. Add the following lines just above ganttChartElement.appendChild(contentFragment);:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da577af5c0b3ff6ece13a6e16da20000/href">https://medium.com/media/da577af5c0b3ff6ece13a6e16da20000/href</a></iframe><p>We use for loops to create string arrays of the &lt;option&gt; tags that we need. We then find their &lt;select&gt; tags in the document fragment stored in the contentFragment variable and add the options to their respective &lt;select&gt; tags. If you run your local server now, you should see the following basic skeleton of our app in your browser window:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Xo6TWFo6z0ynvpxz.png" /></figure><h3>Creating the Gantt chart grid</h3><p>Let’s create the Gantt chart grid that will display our tasks, a timeline, and our task durations. The diagram below has six numbered arrows that show the order in which the columns, rows, and task duration elements will be created. The creation of each part of the grid will be performed with functions. These six functions will be called in the createGrid function, which we will soon create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dfzWgY-4cSu2OVmjK_UOng.png" /></figure><p>Let’s now select the tasks and time period containers from the content fragment, create the createGridfunction, and call it. Add the following lines just above ganttChartElement.appendChild(contentFragment);:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f45931ba8df2ef92ce43324eb8eab2c/href">https://medium.com/media/1f45931ba8df2ef92ce43324eb8eab2c/href</a></iframe><p>We first get the tasks and time periods containers from the document fragment, contentFragment. We also get the “add task” and “add task duration” form elements, as well as the “add task duration” &lt;select&gt; element. We will use these elements later.</p><p>We then define the createGrid function. In this function, we determine the planning time period based on the values of the “From” and “To” &lt;select&gt; values. We then use our utility function monthDiff to determine how many months the planning time period extends over. If the “From” date is greater than the “To” date, the monthDiff function returns zero.</p><p>Each time createGrid is called, we clear the containerTasks and containerTimePeriods inner HTML. We do this so that when we update the tasks or task durations and re-create the grid by calling createGrid, the old contents that showed the previous state are removed. We then call the six functions required to create the columns, rows, and task duration elements. The functions are commented out for now. As we define each function, you can uncomment the function call to see its effect on the grid creation. After defining the createGrid function, we call it for its initial render.</p><p>Let’s define the six functions called in createGrid now, one by one.</p><h3>Creating task rows</h3><p>Add the following function below ganttChartElement.appendChild(contentFragment);:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfdc7c0d7f42f597dd6eb95261cacaf9/href">https://medium.com/media/dfdc7c0d7f42f597dd6eb95261cacaf9/href</a></iframe><p>First, we create three empty rows. We then create a row for each task. Each task row has two children: an &lt;input&gt; element and a delete button. The value of the input is the task name. We’ve used an input here so that it can be edited easily. We also add the tasks as options for the task &lt;select&gt; element in the “add task” form.</p><p>You will be able to see the populated task rows in your app now. Make sure to uncomment the createTaskRows() function call in the createGrid function. We still need to make the task edit and delete functional.</p><h3>Adding months</h3><p>Let’s add function two now. Add the following createMonthsRow function below the createTaskRows function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6650e3851d3d3717d51dcff85a01640b/href">https://medium.com/media/6650e3851d3d3717d51dcff85a01640b/href</a></iframe><p>Make sure to uncomment the createMonthRow() function call in the createGrid function.</p><p>The startMonth and numMonths arguments determine how many month columns there will be and where the months start. The number of columns is dynamic because the user can change the time period. Each time a time period is selected, the number of columns in the containerTimePeriods container is determined based on the number of months in the time period. We use the CSS property grid-template-columns to make each month’s column take up one fraction of the container width so that the container is divided evenly into columns for each month.</p><p>For each month, we create a new time period row. We add a &lt;span&gt; element to it as a child. This span element is centered vertically in the row and contains the label for the month and year.</p><p>You will be able to see a single row with the text “Jan 2022” in your app now. However, changing the time period date range will not update the months. We need to add event listeners to listen for a change in the date range so that we can dynamically update the grid.</p><p>Add the following event listeners below the createMonthsRow function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c825fe9266d8f33e788ce1656d214ba/href">https://medium.com/media/7c825fe9266d8f33e788ce1656d214ba/href</a></iframe><p>We listen for the “change” event on the time period &lt;select&gt; tags to check if the year and month ranges have changed. If they have, we re-create the grid by calling the createGrid function.</p><p>You will now be able to see how the time period rows update when the planning time period is changed. For large time periods, there is a horizontal scroll in the grid container with the ID “gantt-grid-container__time”. If an invalid time period is selected, for example from Jan 2023 to Jan 2022, only the first month of the “From” date will be displayed.</p><h3>Adding days of the month</h3><p>Let’s add function three now. Add the following createDaysRow function above the “change” event listeners:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d22a69a845579a43e6d1eefdc2953fa/href">https://medium.com/media/9d22a69a845579a43e6d1eefdc2953fa/href</a></iframe><p>Make sure to uncomment the createDaysRow() function call in the createGrid function.</p><p>This function loops through the number of months provided as an argument and creates a time period element, timePeriodEl, for each month. We create a Date object for the start month, which is stored in the month variable. In each iteration through the number of months, we increase the date of the month variable by one month using the setMonth method of the Date object.</p><p>We have a nested loop for creating the days of each month. The number of days in each month is calculated using our getDaysInMonth utility function. We then loop through each day of the month and create a day element &lt;div&gt; tag called dayEl. We create a &lt;span&gt; element that displays the day value. We add it as a child of the day element. We then add the day element as a child to the time period element for the given month.</p><p>If you view your app now, you will see that the days of the month cells are centered vertically. This is because the container with the “gantt-grid-container__time” ID has its display property set to grid. We will need this later for the drag-and-drop container that we will add inside of the grid. Once we add all of the rows, the rows will be aligned correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rlWnfLqQsulDhDpj.png" /></figure><h3>Adding days of the week</h3><p>Let’s add the fourth function. Add the following createDaysOfTheWeekRow function above the “change” event listeners:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc74bdc36f7bbf72beee4a6c1209cb1a/href">https://medium.com/media/bc74bdc36f7bbf72beee4a6c1209cb1a/href</a></iframe><p>Make sure to uncomment the createDaysOfTheWeekRow() function call in the createGrid function.</p><p>This function is similar to the previous createDaysRow function, the difference being that we add the days of the week instead of the day of the month number to the &lt;span&gt; element. We use our dayOfTheWeek utility function to determine the day of the week, which is displayed as a capitalized string of the first letter of its name. We use the current year, month, and day to calculate which day of the week it is. The dayOfTheWeek utility function makes use of the Date method getDay to determine this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qca4wNxhIGcxb8RO.png" /></figure><h3>Creating a time period container</h3><p>Let’s add the fifth function. Add the following createTaskRowsTimePeriods function above the “change” event listeners:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/876a99910fe1ffc857d2d5e87b9da579/href">https://medium.com/media/876a99910fe1ffc857d2d5e87b9da579/href</a></iframe><p>Make sure to uncomment the createTaskRowsTimePeriods() function call in the createGrid function.</p><p>This function creates a dayElContainer &lt;div&gt; element that will be the drop zone for the draggable task duration elements. We use the same grid-template-columns CSS styling that we used in the createMonthsRow function for the containerTimePeriods container. This is done so that the number of columns in the container is determined by the number of months in the selected time period.</p><p>We then create a row for each task by iterating through the tasks. For each task row, we loop through the months. For each month, we loop through each day of the month and create an empty cell. This nested loop is similar to the loops we used for the previous two functions: createDaysRow and createDaysOfTheWeekRow.</p><p>For each empty cell, we color the cell differently if it is a weekend day. We also add task and date <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/data-*">data attributes</a>. These will be used for positioning our task durations on the grid.</p><h3>Adding task durations</h3><p>Let’s add the sixth and final function that is called in the createGrid function, which will add the task durations as horizontal bars on our grid. Add the following addTaskDurations function above the “change” event listeners:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b0ce263b8c86ae8c114f6a024077828/href">https://medium.com/media/0b0ce263b8c86ae8c114f6a024077828/href</a></iframe><p>Make sure to uncomment the addTaskDurations() function call in the createGrid function.</p><p>For each taskDuration passed into our Gantt chart component, we find the start position of where to place the task duration on our grid. This is stored in the startCell variable. We use our createFormattedDateFromDate utility function to convert each task duration’s start property, which is a Date object, into a string. The task duration task and start date is used to find the correct starting position on the grid by finding the cell with the matching data attributes for the task duration. If the start cell is found, we call the createTaskDurationEl function, which will create the task duration element and add it as a child to the cell at its starting position in the grid. Let’s now define this function. Add the createTaskDurationEl below the addTaskDurations function declaration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ac36c6a5cdd23e56f17d242fa3cd263/href">https://medium.com/media/1ac36c6a5cdd23e56f17d242fa3cd263/href</a></iframe><p>We pass in the task duration object and the start cell element as arguments. The dayElContainer element will be the drop zone for our task durations once we add drag-and-drop functionality.</p><p>We create a task duration element and give it the “taskDuration” class for CSS styling. It has a z-index of 1 so that it is placed on top of the grid. Its position is absolute, and the cell that it is placed on has a relative position so that the task duration is placed on its start cell.</p><p>In order for the task duration to span across the correct number of cells, we make use of our dayDiff utility function to determine how many days our task duration is. We use this value to calculate the width of the task duration element by setting its width to 100% of the cell width, which is a single day, multiplied by the number of days. The function returns days, which we will use when we add drag-and-drop functionality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TksPJn1GolO_sbRY.png" /></figure><h3>Making the Gantt chart functional</h3><p>Now that we have created our Gantt chart UI, let’s turn our attention to how to make the Gantt chart functional.</p><h3>Adding drag-and-drop functionality to task durations</h3><p>Let’s add drag-and-drop functionality to our task durations so that we can change the position of the task duration elements on the grid. Add the following lines inside the createTaskDurationEl function, just above the startCell.appendChild(taskDurationEl); line:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60e7ba9c7fd227b891846fa83ad1e48a/href">https://medium.com/media/60e7ba9c7fd227b891846fa83ad1e48a/href</a></iframe><p>The first thing we do is set the draggable property of the taskDurationEl to true. We don’t need this property for our drag and drop to work, but it is good for UX because it creates a “ghost” image of the task duration element that is attached to the mouse cursor as it is being dragged.</p><p>We then add two event listeners to the taskDurationEl: “dragstart” and “dragend”. When the task duration element is being dragged, we add the class “dragging” to it. When the drag ends, we remove the class. We do this to style the task duration element that is being dragged. In our style.js file, we gave elements with the “dragging” class an opacity of 0.5. If you try to drag a task duration element and check the “Elements” tab in your dev tools, you will see that the “dragging” class is added when the drag starts and removed when the drag ends.</p><p>We also set the taskDurationElDragged variable to the task duration element that is being dragged. We will use this value later to remove the task duration element that was dragged, create a new task duration for the new position on the grid, and to update the task durations.</p><p>If you try to drag a task duration, you will see that the cursor will be changed to the “not-allowed” icon. This is because dragging and dropping an element inside of another element is disabled by default. You can read more about this in the following article: <a href="https://web.dev/drag-and-drop/">Using the HTML5 Drag and Drop API</a>. To remove this default behavior, add the following lines of code under the “dragend” event listener we just added.:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2623700cd4d58ef169bb95b645408511/href">https://medium.com/media/2623700cd4d58ef169bb95b645408511/href</a></iframe><p>This adds a “dragover” event listener to the dayElContainer, which is our drag-and-drop zone. This event fires continuously as an element is dragged over it. We prevent the event default behavior using the preventDefault method. Our cursor will now not show the “not-allowed” icon in our drag-and-drop zone.</p><p>Let’s get the drag and drop to work. In the createTaskRowsTimePeriods function, add the following line of code just above the timePeriodEl.appendChild(dayEl); line:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09896cffbb7c2a4e57a810103e880e28/href">https://medium.com/media/09896cffbb7c2a4e57a810103e880e28/href</a></iframe><p>We add the <a href="https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/ondrop">onDrop</a> attribute to define the <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/drop_event">drop</a> event handler for each cell in the drag-and-drop zone of the grid. The onTaskDurationDrop function is called when an element is dropped on a cell. Let’s define the onTaskDurationDrop function. Add the following lines below the createTaskDurationEl function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d25062338d12fa4ccd9d66c4f1637d91/href">https://medium.com/media/d25062338d12fa4ccd9d66c4f1637d91/href</a></iframe><p>We determine which cell the task duration element has been dropped on by accessing the target property of the event. We prevent adding the task duration to another task duration by checking if the targetCell has a draggable attribute. Only the task durations have this attribute.</p><p>We then find the task in the task durations array by using the dragged task duration element’s id. The taskDurationElDragged was determined at the start of the drag. We then get the task duration’s name and start date from its data attributes. We remove it from the DOM and create a new task duration element for the task duration’s new position using the createTaskDurationEl function.</p><p>Lastly, we update the taskDurations by removing the dragged task duration and adding the updated dragged task duration with its new position data.</p><h3>Making task durations deletable</h3><p>Now let’s make our task durations deletable by pressing the delete button when the task duration is in focus. Add the following lines in the createTaskDurationEl function, above the startCell.appendChild(taskDurationEl); line:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9cf635014f9a362a920867f8610ccbe/href">https://medium.com/media/a9cf635014f9a362a920867f8610ccbe/href</a></iframe><p>We set the task duration element’s <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex">tabindex</a> attribute to zero so that it can be focused, and add it to the sequential keyboard navigation.</p><p>Our “keydown” event listener listens for when the task duration element is in focus and the delete button is pressed. Should that occur, we call the deleteTaskDuration function. Let’s define this function below the onTaskDurationDrop function definition:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12e8b25268f6fd7da162238e2baf55b1/href">https://medium.com/media/12e8b25268f6fd7da162238e2baf55b1/href</a></iframe><p>In this function, we determine which task to delete by checking which task duration was in focus using the event’s target property. We then remove it from the DOM and update the task durations by filtering the deleted task duration out of the task durations array.</p><p>You will be able to delete your task durations now by clicking on them and pressing the delete button.</p><h3>Making the “Add task duration” form functional</h3><p>Let’s make the “Add task duration” form functional so that we can add task durations to our grid. Add the following event listener below the “change” event listeners:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff69b2a6dd86eb0fe5b6a6853e87d2d4/href">https://medium.com/media/ff69b2a6dd86eb0fe5b6a6853e87d2d4/href</a></iframe><p>This listens for a “submit” event on our “Add task duration” form.</p><p>Let’s define the event handler function. Add the following handleAddTaskDurationForm function below the deleteTaskDuration function declaration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6bc7ca736778eca83e761fc66bc84bd9/href">https://medium.com/media/6bc7ca736778eca83e761fc66bc84bd9/href</a></iframe><p>The first thing this event handler function does is prevent the “submit event” default behavior. This prevents the form from being submitted via a GET request, which would cause a page refresh. We would lose the changes that we made as we are not persisting the data changes.</p><p>We then get the new task name, start date, and end date from the form inputs. We create a timestamp using Date.now() to create a unique ID for our new task duration. We then use these values to create a taskDuration object and add it to the task durations data array.</p><p>Lastly, we create a task duration element and add it to the grid, if we can find its start position. You will now be able to add tasks to your Gantt chart component from the form.</p><h3>Making tasks editable</h3><p>The task inputs can be edited, but they do not update the tasks data array, and the edits don’t update options in the “Which task?” &lt;select&gt; element of the “Add task duration” form.</p><p>Let’s first create a function that handles updating the edited tasks. Add the following updateTasks function below the handleAddTaskDurationForm function definition:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cddaa5fc79870dc2da7ac01da8ff6193/href">https://medium.com/media/cddaa5fc79870dc2da7ac01da8ff6193/href</a></iframe><p>We get the id of the task to update from the target event’s parentNode. The target will be the task &lt;input&gt;, which has a parent element with an id attribute set to the task id we set in the createTaskRows function. We then remove the task that was edited from the tasks data array and add a new task with the updated task name to update the tasks. We also sort the tasks by ID, that is, the order in which they are created.</p><p>To call updateTasks when a task input value is changed, we need to add a “change” event listener to each task input. Add the following lines to the createTaskRows function below the taskRowElInput.value = task.name; line:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92c06aa1efdfc2c6eceda7816c61fe62/href">https://medium.com/media/92c06aa1efdfc2c6eceda7816c61fe62/href</a></iframe><p>The tasks data array will be updated when the task input is changed.</p><p>We also need to update the “Which task?” &lt;select&gt; element of the “Add task duration” form. Add the following code to the end of the updateTasks function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12306a7c0ddcfd830e0d5d1e8e299902/href">https://medium.com/media/12306a7c0ddcfd830e0d5d1e8e299902/href</a></iframe><p>This will update the taskSelect &lt;select&gt; element with options that reflect the updated tasks state.</p><h3>Making tasks deletable</h3><p>Now let’s make the delete task buttons work. In the createTaskRows function below taskRowElDelBtn.innerText = “✕”; line, add the following line:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/695e2acb5df093fbad9af06d0bc840e1/href">https://medium.com/media/695e2acb5df093fbad9af06d0bc840e1/href</a></iframe><p>This adds a “click” event listener to each task delete button. Let’s add the deleteTask function that is called when the click event is fired. Add the following deleteTask function below the updateTasksfunction:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4fa78237dd0e171d39a092c3e553024d/href">https://medium.com/media/4fa78237dd0e171d39a092c3e553024d/href</a></iframe><p>This function gets the id of the task from its parentNode, like we did for the &lt;input&gt; in the updateTasks function. We then filter out the task to delete from the tasks data array to update the tasks. We also delete any task durations that are associated with the deleted task by filtering out any task durations that have a task id that matches the deleted task’s id.</p><p>You will now be able to delete tasks by clicking the delete button next to each task name input.</p><h3>Making the “Add task” form functional</h3><p>To make the add task form functional, we will first create a “submit” event listener. Add the following line to the GanttChart function, at the bottom:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3db0bed1df566dfef333cfae926a4642/href">https://medium.com/media/3db0bed1df566dfef333cfae926a4642/href</a></iframe><p>We need to define the handleAddTaskForm function that is called when the “Add task” form is submitted. Add the following handleAddTaskForm function below the handleAddTaskDurationForm function definition:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb98a500da3eac240a8ed347216f520e/href">https://medium.com/media/eb98a500da3eac240a8ed347216f520e/href</a></iframe><p>We first prevent the default “submit” event behavior, and then get the new task name value from the form. We use the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce">reduce</a> array method to determine the new task id. The task id values are numbers that represent the order in which they were created. They are sorted by their id. We find the largest current task id, and then add one to it to create the id for the new task.</p><p>We then call the createGrid function to re-render the grid so that it will show the new task row.</p><p>We now have a working basic Gantt chart component, but you might like to make some improvements to it.</p><h3>Next steps</h3><p>There are many ways you can add to or improve the Gantt chart component. Here are some things that you might want to try:</p><ul><li>Improve the styling. The screenshot shown has some extra CSS not included in the examples above, but which you can find <a href="https://github.com/bryntum/gantt-chart-javascript-tutorial">in the GitHub repository</a>.</li><li>Make the number of days that the task durations span editable.</li><li>Make the tasks reorderable.</li><li>Sanitize the task and task duration data as setting user-supplied data using innerHTML is a security risk.</li><li>Add configuration arguments or properties that will allow a user to easily change properties of the Gantt chart component, such as the styling or theme.</li><li>Persist the data in a database.</li><li>Make the component a web component so that you have a nicely encapsulated custom HTML element.</li></ul><p>A fully featured Gantt chart component that could be used for large projects would include many other advanced features such as:</p><ul><li>Scheduling conflict resolution.</li><li>Handling time-zone differences.</li><li>Grouping of tasks.</li><li>Extra information labels.</li><li>Undo and redo functionality.</li><li>Complex task and task duration customization.</li><li>Exporting to Excel, PDF, or as an image.</li><li>Performance optimizations for big data sets.</li><li>Integration with other project management tools, such as task boards.</li></ul><h3>Build or buy?</h3><p>This article gives you a starting point for building your own Gantt chart. If you’re instead looking to buy an off-the-shelf battle-tested solution that just works, take a look at some examples of our <a href="https://bryntum.com/examples/gantt">Bryntum Gantt Chart</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd1612ab5472" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bryntum/creating-a-gantt-chart-with-vanilla-javascript-bd1612ab5472">Creating a Gantt chart with vanilla JavaScript</a> was originally published in <a href="https://medium.com/bryntum">Bryntum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3 ways to style radio buttons with modern CSS]]></title>
            <link>https://medium.com/bryntum/3-ways-to-style-radio-buttons-with-modern-css-94bc1eebd6f0?source=rss----32ca805267d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/94bc1eebd6f0</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Mats Bryntse]]></dc:creator>
            <pubDate>Mon, 11 Apr 2022 10:56:22 GMT</pubDate>
            <atom:updated>2022-04-11T10:53:15.459Z</atom:updated>
            <content:encoded><![CDATA[<p>Styling native radio input elements cross-browser is a bit more painful than it should be. Over the years, lots and lots of blogs have discussed this topic and provided various <a href="https://dev.to/felipperegazio/styling-native-radio-and-checkbox-inputs-css-only-58ci">styling workarounds</a>. Most solutions involve showing additional pseudo elements such as</p><pre>[type=radio]:checked::before { <br>    content: &quot;&quot;; <br>    width: 14px; <br>    height: 14px; <br>    background-color: #ffa500; <br>    position: absolute; <br>    top: 2px; <br>    left: 2px; <br>}</pre><h3>Modern CSS to the rescue</h3><figure><img alt="CodePen" src="https://cdn-images-1.medium.com/max/1024/1*B9diR1RrfnHzJixCiWEyHw.png" /><figcaption>The CodePen (link below)</figcaption></figure><p>With some simple and modern CSS, we can now style radio button input elements even easier. Below are three different options, each having its pros and cons. You can try out the different options in <a href="https://codepen.io/bryntum/pen/VwydOeQ">this CodePen</a>.</p><h3>Using accent-color</h3><p>The CSS property <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/accent-color">accent-color</a> styles some native elements by changing their accent color. This property is <a href="https://caniuse.com/?search=accent-color">widely supported</a> in 2022. But it is not fully supported and most browsers only started supporting it in 2021.</p><pre>body { accent-color: red; }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/0*Lfc8Z1TSG67jd4xh.png" /></figure><p><strong>Pros</strong></p><ul><li>Simple to use</li></ul><p><strong>Cons</strong></p><ul><li>Low stylability</li><li>Not fully supported</li></ul><h3>Using box-shadow</h3><p>Both the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow">box-shadow</a> and the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/outline">outline</a> solutions are accomplished by hiding the native appearance of the element. And then with a combination of <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/background">background</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/border">border</a> and an outer circle, we create a new appearance which will is easier to style.</p><pre>input { <br>    /* The native appearance is hidden */ <br>    appearance: none; <br>    -webkit-appearance: none; <br>    <br>    /* For a circular appearance we need a border-radius. */ <br>    border-radius: 50%; </pre><pre>    /* The background will be the radio dot&#39;s color. */ <br>    background: #FF572233; </pre><pre>    /* The border for spacing between the dot and the circle */                 border: 3px solid #FFF; </pre><pre>    /* box-shadow with no offset and no blur =&gt; an outer circle */ <br>    box-shadow: 0 0 0 1px solid #FF5722; }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/290/0*evzHXS5ub78aZE9-.png" /></figure><p>Note that in some cases the box-shadow can be clipped by it’s container. In these cases, a margin can be a good solution.</p><p><strong>Pros</strong></p><ul><li>Full support</li><li>High stylability</li></ul><p><strong>Cons</strong></p><ul><li>Scales badly in some environments.</li></ul><h3>Using outline</h3><p>The outline solution applies the same technique as the box-shadow solution, but creates the outer circle using the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/outline">outline</a> property instead. Outline is <a href="https://caniuse.com/?search=outline">widely supported</a>, but not in combination with border-radius which does not work as expected in Safari.</p><p>Note that the outline is the browser’s default focus style. When changing the outline style, you should always have accessibility in mind.</p><pre>input { <br>    appearance: none; <br>    -webkit-appearance: none; <br>     border-radius: 50%; <br>     background: #e8e8e8; <br>     border: 3px solid #FFF; <br>     /* The outline will be the outer circle */ <br>     outline: 1px solid #999; <br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/196/0*oUxYCcsYJM0ZB0GX.png" /></figure><p><strong>Pros</strong></p><ul><li>Scales better than box-shadow</li><li>High stylability</li><li>Does not affect layout</li></ul><p><strong>Cons</strong></p><ul><li>No Safari support.</li></ul><h3>Which one to choose?</h3><p>In the upcoming 5.1 release, we at Bryntum decided to use the `box-shadow` option in our <a href="https://bryntum.com/docs/scheduler/api/Core/widget/Radio">Radio button</a> widget. It provides a reliable cross-browser appearance and it is compatible with a bit older browsers. You can see this in action in our conflict resolution dialog in the <a href="https://bryntum.com/examples/scheduler-pro/conflicts/">Scheduler Pro</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*v-_1-t8Glda-hoV9.png" /></figure><p><em>Originally published at </em><a href="https://www.bryntum.com/blog/3-ways-to-style-radio-buttons-with-modern-css/"><em>https://www.bryntum.com</em></a><em> on April 11, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94bc1eebd6f0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bryntum/3-ways-to-style-radio-buttons-with-modern-css-94bc1eebd6f0">3 ways to style radio buttons with modern CSS</a> was originally published in <a href="https://medium.com/bryntum">Bryntum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Announcing technical preview of Siesta 6]]></title>
            <link>https://medium.com/bryntum/announcing-technical-preview-of-siesta-6-bryntum-334dcb5452e2?source=rss----32ca805267d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/334dcb5452e2</guid>
            <dc:creator><![CDATA[Mats Bryntse]]></dc:creator>
            <pubDate>Tue, 17 Aug 2021 11:56:58 GMT</pubDate>
            <atom:updated>2021-08-17T13:04:12.216Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NqM1o3Ahsrgm6R2Ya0SUVg.png" /><figcaption>Siesta 6 Tech Preview</figcaption></figure><p>Today we are thrilled to announce the availability of a technical preview of a new major version of our Siesta testing tool. The siesta-6.0.0-alpha is now <a href="https://www.npmjs.com/package/@bryntum/siesta">available on npm</a>.</p><p>Version 6 is a complete rewrite, using a modern technology stack and incorporating more than a decade of test driven development experience. This means no IE/legacy Edge support. This also means backward compatibility will not be fully preserved.</p><p>Why a full rewrite, breaking backward compatibility? We did not take this decision lightly. Siesta was created more than 11 years ago, roughly at the same time as Node.js and NPM, and has maintained backward compatibility ever since. Since the foundation of the Siesta code base was written to support IE6 (!), it is now very outdated when compared to latest ES language versions. Making any significant changes to it has become prohibitively complex. Fixing one part of the code, for example changing the class system from <a href="http://joose.it/">Joose</a> to <a href="https://github.com/microsoft/TypeScript">TypeScript</a>, would require rewriting all source files. Same goes for the build process, which is currently using Perl scripts, Sencha CMD and manual file concatenation.</p><p>To move forward and keep up with the pace of modern Web evolution, we decided to do a complete rewrite. We will do our best to make the migration from 5 to 6 straightforward and simple.</p><h3>Siesta 5 goes into maintenance mode</h3><p>Siesta 5 will remain supported for the foreseeable future. All the Bryntum products have Siesta 5 test suites (thousands of tests in total) and we rely fully on Siesta 5 to keep our releases <a href="https://github.com/bryntum/support">green and stable</a>. We will continue to fix bugs and release patch versions as requested by our community and customers.</p><h3>Changes in licensing</h3><p>Siesta 5 exists as two packages — siesta-lite which is freely available on <a href="https://www.npmjs.com/package/siesta-lite">npm</a> under a proprietary license, and the full<a href="https://www.bryntum.com/products/siesta">siesta</a> version– a paid version under a proprietary license.</p><p>In version 6, the names and licensing of these two packages will change. The previously free version siesta-lite becomes just siesta and it is now open-source ( <a href="https://opensource.org/licenses/MIT">MIT</a> licensed), available on npm as <a href="https://www.npmjs.com/package/@bryntum/siesta">@bryntum/siesta</a>. The commercial siesta package becomes siesta-plus and it will remain under the current proprietary license.</p><p>With this change, we aim to turn Siesta into a truly open source testing tool, with a broad community involvement.</p><h3>Project status</h3><p>We consider the server-side testing functionality to be stable and feature complete. Siesta 6 can be used right now to write tests for Node.js/Deno projects.</p><p>However, the released version is labeled as “alpha” because the browser-side testing has not yet reached feature parity with version 5. Tests can be launched in browsers, but there is no simulation of user actions on the web page. In the upcoming releases we will prioritise UI testing as well as building the graphical user interface for the Siesta web app.</p><p>To sum up — if you need to write tests for Node.js / Deno, please consider this release as a solid “beta”. For browser tests — you can only run generic tests without user action simulation, that’s why we labeled it an “alpha”.</p><h3>What’s new</h3><p>In version 6, Siesta becomes a truly ubiquitous testing tool — it can run tests in browsers, Node.js and <a href="https://deno.land/">Deno</a>. Tests written for “ <a href="https://en.wikipedia.org/wiki/Isomorphic_JavaScript">isomorphic</a>” code can be run <em>unmodified</em> in all these three target environments! One test tool to run them all 😈</p><p>In version 6 we are focusing on usage ergonomics. We have restyled the console output completely, it is now properly structured as a tree. The assertion list now goes below the test file name (in Siesta 5 it was above the test file). We have also added source code context for failed assertions, to make it easier to locate the failure. This is a relatively small addition, but one which greatly improves ergonomics.</p><p>During our 11 years of TDD experience, we found that when examining test results, most of the time is spent figuring out the difference between data objects being compared. Siesta 5 had a very weak implementation of this use case. In version 6 we have addressed it properly and Siesta now provides a precisely formatted diff view for deep equality assertions.</p><p>To illustrate the above, see the Siesta 5 screenshot for the isDeeply assertion below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*iGn9Ava4d-7skAMS.png" /></figure><p>You can definitely say that not much attention was put into making the output easy to grasp. When writing the “old” Siesta we were busy dealing with Rhino as the server-side runtime and writing our own bundling stack. Colors are arbitrary, important information like the test file name is not highlighted, and the one-line JSON text output quickly becomes unreadable.</p><p>In contrast, please see the screenshot of the same assertion in Siesta 6:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*IAQMq5hCU0-gv68U.png" /></figure><p>Hopefully the picture talks for itself. It is worth pointing out that the deep diff provided by Siesta 6 remains readable for any input data size.</p><p>The deep equality assertion itself has also been greatly improved. It now supports comparing cyclic data structures, plus all built-in JavaScript data types like Map and Set.</p><p>We have also revamped the output colors, added themes and made them configurable. Siesta 6 now has three built-in themes — dark, light and universal. These themes are built using standard SASS, with plenty of variables to control the UI appearance, should you want to tweak the UI.</p><h3>Next steps</h3><p>Our immediate goal is to reach feature parity with version 5 in the area of Web testing. This includes building the graphical UI, adding support for simulating user actions, and the user actions recorder.</p><p>We also plan to add support for running tests directly on cloud platforms like Azure and AWS to achieve maximum parallelization. This feature will be added to the commercial package siesta-plus (aiming to be released in 2022).</p><p>If you have any particular feature you would like to see prioritized in Siesta, please leave a comment below or drop us a line in the <a href="https://github.com/bryntum/siesta/issues">issues tracker</a>.</p><p>Stay tuned for future releases.</p><p>Happy testing!</p><h3>Connect</h3><p>Homepage: <a href="https://siesta.works/">https://siesta.works</a></p><p>NPM package: <a href="https://www.npmjs.com/package/@bryntum/siesta">https://www.npmjs.com/package/@bryntum/siesta</a></p><p>Github: <a href="https://github.com/bryntum/siesta">https://github.com/bryntum/siesta</a></p><p>Discord channel: <a href="https://discord.gg/6mwJZGnwbq">https://discord.gg/6mwJZGnwbq</a></p><p><em>Originally published at </em><a href="https://www.bryntum.com/blog/announcing-technical-preview-of-siesta-6/"><em>https://www.bryntum.com</em></a><em> on August 17, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=334dcb5452e2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bryntum/announcing-technical-preview-of-siesta-6-bryntum-334dcb5452e2">Announcing technical preview of Siesta 6</a> was originally published in <a href="https://medium.com/bryntum">Bryntum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Five Fast JavaScript Data Grids — A Performance Review]]></title>
            <link>https://medium.com/bryntum/five-fast-javascript-data-grids-a-performance-review-22b456ba423b?source=rss----32ca805267d8---4</link>
            <guid isPermaLink="false">https://medium.com/p/22b456ba423b</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Mats Bryntse]]></dc:creator>
            <pubDate>Fri, 06 Sep 2019 14:07:48 GMT</pubDate>
            <atom:updated>2019-09-06T14:06:06.221Z</atom:updated>
            <content:encoded><![CDATA[<h3>Five Fast JavaScript Data Grids — A Performance Review</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*x3agnA4c1nQcOVCn.png" /><figcaption><em>An example of a Data Grid.</em></figcaption></figure><p>It is hard to imagine a modern web app that does not involve a data grid component to display and filter the data. In this article, we compare the performance of some of the most popular JavaScript grid components on the market, measuring both the initial render time and the scrolling performance. We also describe the methodology used and there is a <a href="https://github.com/bryntum/grid-performance">GitHub repo</a> where you can see the code used.</p><h3>The Grid Components</h3><p>The following popular data grids were used in this comparison:</p><ul><li>Ag-grid (<a href="https://www.ag-grid.com/">ag-grid.com</a>)</li><li>Bryntum Grid (<a href="https://www.bryntum.com/products/grid">bryntum.com/products/grid</a>)</li><li>DevExtreme Grid (<a href="https://js.devexpress.com/Overview/DataGrid">js.devexpress.com/Overview/DataGrid</a>)</li><li>DHTMLX Grid (<a href="https://dhtmlx.com/docs/products/dhtmlxGrid">dhtmlx.com/docs/products/dhtmlxGrid</a>)</li><li>Ext JS Modern Grid (<a href="https://www.sencha.com/products/extjs">sencha.com/products/extjs</a>)</li></ul><h3>Benchmarking Methodology</h3><p>To make the comparison as fair as possible the following actions were taken:</p><ul><li>Two test cases were created per grid, one with locked/fixed/pinned columns and one without.</li><li>The same dataset was used for all grids, consisting of 10,000 JSON objects with ten fields each.</li><li>Columns were configured as similar as possible for all grids. Ten columns, some with custom settings:</li><li><em>One column with cells that has their background color set from data.</em></li><li><em>One column with a custom progress bar.</em></li><li><em>One date column.</em></li><li><em>One boolean column displaying Yes/No.</em></li><li>Some grids ship with features enabled by default, some require you to manually enable them. For fairness, all non-essential features such as sorting, grouping, filtering and so on were turned off</li><li>All grids were rendered into a 1280 x 1024 px sized container.</li><li>All measurements were taken on a 2016 MacBook Pro 13&quot; (2 GHz Intel Core i5, 8GB RAM).</li><li>Scrollbars were turned on.</li></ul><h3>Measuring</h3><p>JavaScripts performance.now() was used to measure time in the benchmarks.</p><h3>Initial Rendering</h3><p>The following steps were taken to measure initial rendering:</p><ol><li>Everything was first loaded on the page, such as <a href="https://dzone.com/refcardz/css3?chapter=1">CSS</a>, <a href="https://dzone.com/refcardz/functional-programming-with-javascript">JavaScript</a>, and the used dataset.</li><li>A timer was started.</li><li>A grid instance was created and populated with the column set and the already loaded dataset.</li><li>When the grid was fully rendered on screen, the timer was stopped.</li></ol><p>A small utility class was used to achieve this, the important part of its source:</p><pre>export class RenderTimer {<br>    static start({ sync = true, callback }) {<br>        this.start = performance.now();<br>        callback &amp;&amp; callback();<br>        if (sync) this.stop();<br>    }<br>    static stop() {<br>        const elapsed = performance.now() - this.start;<br>        console.log(elapsed);<br>    }<br>}</pre><p>And example of its usage:</p><pre>// For a grid that renders sync<br>RenderTime.start({<br>  callback() {<br>    new Grid({<br>       // config...<br>    });<br>  }<br>});</pre><pre>// For a grid that renders async<br>RenderTimer.start({<br>  sync : false,<br>  callback() {<br>    new Grid({<br>       // config...<br>       onRenderDone() {<br>          // async rendering done<br>         RenderTimer.stop();<br>       }<br>    });<br>  }<br>});</pre><h3>Scrolling</h3><p>To measure scroll performance, two utility classes are used. One that makes the grid scroll on a timer and one that measures the FPS. Below you can see the source for the scroller:</p><pre>export class Scroller {<br>    static scroll({ element, distance = 50000, speed = 5, maxSpeed = 1000, acceleration = 1, callback, scrollFn }) {<br>        let scrollTop = 0;<br>        const intervalId = setInterval(() =&gt; {<br>            if (scrollFn) {<br>                scrollFn(scrollTop)<br>            } else {<br>                element.scrollTop = scrollTop;<br>            }<br>            scrollTop += speed;<br>            if (speed &lt; maxSpeed) speed += acceleration;<br>            if (scrollTop &gt; distance) {<br>                clearInterval(intervalId);<br>                callback &amp;&amp; callback();<br>            }<br>        }, 1);<br>    }<br>}</pre><p>It either directly scrolls an element or provides a scrollFn callback for grids that do not have native scrolling. Scrolling starts at 5px per update, accelerating all the way up to 1000px, this way mimicking flick scrolling on a touchpad or an unlocked mouse wheel. At a predefined distance of 50,000px, the scrolling stops and a callback is called.</p><p>Usage example:</p><pre>Scroller.scroll({<br>  element : document.querySelector(&#39;.scroller-selector&#39;),<br>  callback() {<br>    // scrolling done <br>  }<br>});</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MT-xaexTZ5ioDJyG.gif" /></figure><p>Please note that programmatically triggering the scroll-like this makes it happen on the main thread, in sync with the UI. When an actual user scrolls using the touchpad, it happens async on another thread. The difference might not be obvious, but because it is done programmatically here the UI will always be up to date. Only it will happen faster or slower depending on the grid. In real life, scrolling is not blocked by UI updates which leads to whiteouts instead.</p><h3>FPS</h3><p>To measure FPS (frames per second) a utility class that utilizes requestAnimationFrame is used. It measures the time taken to reach the scroll destination, counts the number of frames run and calculates FPS. Source redacted to save some space:</p><pre>export class FPS {<br>    static start() {<br>        this.start = null;<br>        this.frameCount = 0;<br>        this.running = true;<br>        requestAnimationFrame(this.frameCounter);<br>    }<br>    static stop() {<br>        this.running = false;<br>        const<br>            elapsed = performance.now() - this.start,<br>            fps = this.frameCount / (elapsed / 1000);<br>        console.log(fps);<br>    }<br>    static frameCounter() {<br>        const time = performance.now();<br>        if (FPS.start === null) {<br>            FPS.prevFrameTime = FPS.start = time;<br>        } else {<br>            FPS.frameCount++;<br>        }<br>        FPS.prevFrameTime = time;<br>        if (FPS.running) {<br>            requestAnimationFrame(FPS.frameCounter)<br>        }<br>    }<br>}</pre><p>Usage:</p><pre>FPS.start();<br>// actions...<br>FPS.stop();</pre><h3>Results</h3><p>First up, initial rendering. Scroll down for the scroll performance results.</p><h3>Initial Rendering</h3><p>First the results for initial rendering, <strong>without</strong> locked/fixed/pinned columns:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wq1Ocx6OkiOWRtSn.png" /></figure><p>As can be seen above, dhtmlX is the fastest for the initial rendering phase, with Bryntum as the clear runner-up. For all practical applications though, the difference between the best and the worst, in this case, is negligible. A real world application loading and displaying 10,000 records will spend much more time retrieving the data from the backend than the time it takes to display it.</p><p>Reviewing the results for initial rendering <strong>with</strong> locked/fixed/pinned columns we can see that the relative ranking is the same, but it takes a wee bit longer to render:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ijuSx5Lq0X-UWNYl.png" /></figure><p>ExtJS renders pretty much slower in this case, but it is not noticeable unless you measure it. Still fast enough across the board.</p><h3>Scrolling FPS</h3><p>When it comes to FPS there are bigger differences between the grids. Lets first look at the scenario <strong>without locked/fixed/pinned</strong> columns:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7_QBN1JPIOX60Br8.png" /></figure><p>Ag-grid, Bryntum and Ext JS are pretty much tied for the lead, averaging at around 60 frames per second which is as good as it gets! DevExtreme and dhtmlX lag behind at 38 and 25 FPS respectively.</p><p>In contrast to the initial rendering performance, these performance differences are easy to spot with the eye. Scrolling fast in a grid that has low FPS leads to whiteouts and poor user experience.</p><p>Now for the final round of results, we have the grids with <strong>locked/fixed/pinned</strong> columns. This case is especially interesting for anyone building or using Scheduler or Gantt components as such components always have a fixed left section with the tabular data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*n6wFIiBSh7VBQIY8.png" /></figure><p>Bryntum almost manages to maintain 60 frames per second, while Ag-grid and ExtJS are a few frames behind. Still very fast though, kudos to the developers of both libraries. DevExtreme and dhtmlX lag further behind, probably because of how locked sections are implemented in those grids.</p><h3>Summing Up</h3><p>This article is not comparing features of the grids, but if you care about performance as much as we do then this post might be helpful when picking which grid to use. Bryntum Grid performs good both initially and while scrolling, but as mentioned above the initial rendering time is good enough across the board. With that in mind it is hard to pick a single winner, so let’s call this a tied 1st place between Ag-grid, Bryntum and Ext JS.</p><h3>Disclaimer</h3><p>All measurements were done the same way for each grid and results are reported honestly, but Johan Isaksson who wrote this article is working for Bryntum. For transparency, all the code used is available on GitHub. Feel free to try it out yourself: <a href="https://github.com/bryntum/grid-performance">https://github.com/bryntum/grid-performance</a></p><p><em>Originally published at </em><a href="https://dzone.com/articles/data-grid-performance-comparison"><em>https://dzone.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22b456ba423b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bryntum/five-fast-javascript-data-grids-a-performance-review-22b456ba423b">Five Fast JavaScript Data Grids — A Performance Review</a> was originally published in <a href="https://medium.com/bryntum">Bryntum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>