RadiantQ jQuery Gantt Package
How to communicate with gantt component from your own component in React?
Previous Topic  Next Topic 

Sometimes, one component may be depended on any other component. The communication between the components can possible by passing property.

Here is the code that shows how to do that,


class ButtonContainer extends React.Component {

    constructor(props) {

        super(props);

        this.ganttControl = this.props.ganttControl;

    }

  

     // componentWillReceiveProps will updates the newly recevied ganttcontrol props.

    componentWillReceiveProps(nextProps) {

        if (nextProps.ganttControl !== this.ganttControl) {

            if (this.ganttControl !== null)

              this.ganttControl = nextProps.ganttControl;

       }

    }


    // To add a task.

    addRow() {

        var newTask = this.getNewTask();

        this.ganttControl.AddNewItem(newTask);

         //Add the newly added task to Dictionary.

        this.addedTasks.Add(newTask.ID, newTask);

    }

   

    // To return a new task object.

    getNewTask() {

        return {

            "Name": "New Task ",

            "ID": this.ganttControl.Model.GetNewID(),

            "StartTime": new Date("2014/02/02"),

            "Effort": new RQTimeSpan(0, 12, 30, 0, 0),

            "ProgressPercent": 50,

            "Description": "Description of Task"

        };

    }


    render() {

        return (

            <div id="Div1">

                <button id="addRow" onClick={() => this.addRow()}>Add task</button>

            </div>

        );

    }

}

 

class GanttControlCustomDataBinding extends React.Component {

    constructor() {

        super();

        this.state = { ganttControl: null }

    }

   

     // ganttControl data rerendered once the GanttLoaded event was triggered.

    GanttLoaded($gantt_container,ganttControl) {

        this.setState({ ganttControl: ganttControl })

    }

    

       // Here, GanttControlCustomDataBinding renders multiple Component .

    render() {

        return (

               <div>

                <ButtonContainer ganttControl={this.state.ganttControl}/>

                 <GanttControl

                  ...........

                  ............

                 GanttLoaded={(ganttControl) => this.GanttLoaded(ganttControl)}

                 />

            </div>

        );

    }

}

ReactDOM.render(<GanttControlCustomDataBinding />, document.getElementById('container'));


Note: By default ganttControl state value is null and it should be available after the Gantt is loaded. So, updating the state value in "GanttControlCustomDataBinding" component by setState method and this should be listened in your component by using the "componentWillReceiveProps" lifecycle method.



This is illustrated in this samples:


In React                : .\Samples\GanttControlCustomDataBinding\GanttControlCustomDataBinding.jsx.




� RadiantQ 2022. All Rights Reserved.