Enterprise Data Grid & UI Components for Angular, React & Blazor Forums Scheduler Would appreciate any quick pointers on: Scheduler.

  • This topic has 1 reply, 2 voices, and was last updated 1 week ago by admin.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #113443
    emily.thorne91
    Participant

    Is Smart Scheduler compatible with routing? How do I preserve scheduler filters and selections during navigation?

    #113452
    admin
    Keymaster

    Hi,

    Please, find an example below which shows the approach with React

    // React Router + Smart.Scheduler state persistence example
    
    import { useEffect, useRef } from "react";
    import { useNavigate, useLocation } from "react-router-dom";
    import "smart-webcomponents-react/source/styles/smart.default.css";
    import { Scheduler } from "smart-webcomponents-react/scheduler";
    
    export default function SchedulerPage() {
      const schedulerRef = useRef(null);
      const navigate = useNavigate();
      const location = useLocation();
    
      // Restore state on load
      useEffect(() => {
        const scheduler = schedulerRef.current;
    
        const params = new URLSearchParams(location.search);
    
        if (params.get("view")) {
          scheduler.view = params.get("view");
        }
    
        if (params.get("date")) {
          scheduler.date = new Date(params.get("date"));
        }
      }, []);
    
      // Save state before navigation
      const goAway = () => {
        const scheduler = schedulerRef.current;
    
        const params = new URLSearchParams({
          view: scheduler.view,
          date: scheduler.date.toISOString()
        });
    
        navigate(<code>/other-page?${params.toString()}</code>);
      };
    
      return (
        <>
          <Scheduler ref={schedulerRef} />
          <button onClick={goAway}>Navigate</button>
        </>
      );
    }

    Regards,
    Peter

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.