v7.3.0

Binding Bryntum TaskBoard data

Bryntum TaskBoard is a data intensive component that uses several datasets. These datasets usually come from the server and are held in TaskBoard project during the lifetime of the TaskBoard view. There are several ways of populating the project data stores.

Using project transport

ProjectModel supports loading and saving of data in multiple stores with transport config. Loading the stores and saving all changes is done in one request.

Configuring project with transport is the simplest way of binding data to the TaskBoard project stores as seen from the client side, but it does require following a specific protocol on the backend.

The configuration can be as simple as setting the project property like this:

taskboardProps: {
    project : {
        loadUrl  : '/server/load/url',
        syncUrl  : '/server/save/url',
        autoLoad : true
    }
}

<BryntumTaskBoard {...taskboardProps}/>

With this configuration, the data is loaded and saved from and to the above URLs and the data transport is handled automatically.

Binding existing data to the component

When the application already has a server transport layer then the data for TaskBoard is available in application code and it needs to be passed (bound) to the component. One approach is to make the data available as state variables and set these as properties of the React component:

App.js:

import React, { useState } from 'react';

import { taskBoardProps } from './AppConfig';
import { projectData } from './AppData';

import './App.scss';

function App() {

    const [tasks, setTasks] = useState(projectData.tasks);
    const [assignments, setAssignments] = useState(projectData.assignments);
    const [resources, setResources] = useState(projectData.resources);

    return (
        <BryntumTaskBoard
            ref = {taskboard}
            tasks = {tasks}
            assignments = {assignments}
            resources = {resources}
            {...taskBoardProps}
        />
    );
}

export default App;

Here we have state variables, one per data set, together with their setters so whenever a change of data is needed the setter needs to be called with new data as the argument and the change will be immediately reflected in the TaskBoard.

For example:

setTasks(newTasks);
setResources(newResources);
When binding to data, the same principles as for React state applies - an object in the incoming data must be replaced instead of mutated for a change to be detected ( explained by the React team here).

If you cannot follow best practise and have to mutate the objects, you can configure the underlying store with useRawData: false. It will then clone the incoming objects and can thus detect mutations when state is reapplied, trading performance for flexibility (docs here).

Binding existing data to the project

This approach binds data to a standalone TaskBoardProjectModel and then uses this project in TaskBoard. Project has its own markup in the template and it must be assigned to the TaskBoard during initialization.

This approach is suitable for more complex applications that use more than one Bryntum component that share a common project:

App.js:

import React, { useState } from 'react';

import { taskBoardProps, projectProps } from './AppConfig';
import { projectData } from './AppData';

import './App.scss';

function App() {
    const taskboard = useRef();
    const project = useRef();

    const [tasks, setTasks] = useState(projectData.tasks);
    const [assignments, setAssignments] = useState(projectData.assignments);
    const [resources, setResources] = useState(projectData.resources);

    return (
        <>
            <BryntumTaskBoardProjectModel
                ref = {project}
                tasks = {tasks}
                assignments = {assignments}
                resources = {resources}
                {...projectProps}
            />
            <BryntumTaskBoard
                ref = {taskboard}
                project = {project}
                {...taskBoardProps}
            />
        </>
    );
}

export default App;

Here we create a standalone TaskBoardProjectModel (without any rendered output) with properties bound to individual data sets. The project must be assigned to TaskBoard in useEffect which is configured to run only once on component mount.

Note that BryntumTaskBoardProjectModel must be returned first for other components to use it. Otherwise the TaskBoard appears blank, without any data.

Check implementation in inline-data React demo.

Working with Redux

Bryntum components can also be integrated with a Redux Store using the same workflow that you would use to manage the state of a traditional React project.

To see this in action, you can try out our Bryntum Taskboard React + Redux demo.

Contents