React UI Components Documentation

ReactJS Expander Component

The Expander component for ReactJS has header and expandable content section.

Prerequisites

Refer to ReactJS Getting Started before you start with this help topic.

Configuration

The Expander component for ReactJS requires the following imports.

 
import React from 'react';
import ReactDOM from 'react-dom';
import JqxExpander from 'jqwidgets-react/react_jqxexpander.js';

Then we create our component class. Properties and methods are put as ReactJS props.

  
class App extends React.Component {
render () {
return (
<JqxExpander width={300} height={200}>
<div>
Early History of the Internet
</div>
<div>
<ul>
<li>1961 First packet-switching papers</li>
<li>1966 Merit Network founded</li>
<li>1966 ARPANET planning starts</li>
<li>1969 ARPANET carries its first packets</li>
<li>1970 Mark I network at NPL (UK)</li>
<li>1970 Network Information Center (NIC)</li>
<li>1971 Merit Network's packet-switched network operational</li>
<li>1971 Tymnet packet-switched network</li>
<li>1972 Internet Assigned Numbers Authority (IANA) established</li>
<li>1973 CYCLADES network demonstrated</li>
<li>1974 Telenet packet-switched network</li>
<li>1976 X.25 protocol approved</li>
<li>1979 Internet Activities Board (IAB)</li>
<li>1980 USENET news using UUCP</li>
<li>1980 Ethernet standard introduced</li>
<li>1981 BITNET established</li>
</ul>
</div>
</JqxExpander>
)
}
}

Finally we render our class in the desired HTML element:

 
ReactDOM.render(<App />, document.getElementById('app'));

Events Methods & Properties

In order to bind to any event, change any property or call any method, we need a reference to the component.
For that we use the ReactJS "ref" Callback Attribute:

 
<JqxExpander ref='myExpander' width={300} height={200}..... />

Now, when we have a reference, we need to call the desired event/property/method.
This is done in the componentDidMount() ReactJS Component Lifecycle method.

 
class App extends React.Component {
componentDidMount()
{
//your logic
}
render ()
{
return
(
....
)
}
};

Events

The collapsing event is triggered when the Expander is going to be collapsed.

The following example demonstrates how to add an event listener:

 
componentDidMount ()
{
this.refs.myExpander.on('collapsing', (event) =>
{
//your logic
});
}

Methods & Properties

This is how you call methods & props:

  
//Get Methods
let content = this.refs.myExpander.getContent();
//Set Methods
this.refs.myExpander.setContent('Content');
//Get Properties
let height = this.refs.myExpander.height();
//Set Properties
this.refs.myExpander.height(350);

Every component have a method setOptions which accepts a object as an argument. This object contains component settings.

 
this.refs.myExpander.setOptions({
showArrow: false, width: 450, height: 300
})

Every component also have a method getOptions which returns a object containing the component settings.

Expander Examples

Overview

The following example demonstrates how to create a Expander component.

 
import React from 'react';
import ReactDOM from 'react-dom';
import JqxExpander from 'jqwidgets-react/react_jqxexpander.js';
class App extends React.Component {
render () {
return (
<JqxExpander width={300} height={200}>
<div>
Early History of the Internet
</div>
<div>
<ul>
<li>1961 First packet-switching papers</li>
<li>1966 Merit Network founded</li>
<li>1966 ARPANET planning starts</li>
<li>1969 ARPANET carries its first packets</li>
<li>1970 Mark I network at NPL (UK)</li>
<li>1970 Network Information Center (NIC)</li>
<li>1971 Merit Network's packet-switched network operational</li>
<li>1971 Tymnet packet-switched network</li>
<li>1972 Internet Assigned Numbers Authority (IANA) established</li>
<li>1973 CYCLADES network demonstrated</li>
<li>1974 Telenet packet-switched network</li>
<li>1976 X.25 protocol approved</li>
<li>1979 Internet Activities Board (IAB)</li>
<li>1980 USENET news using UUCP</li>
<li>1980 Ethernet standard introduced</li>
<li>1981 BITNET established</li>
</ul>
</div>
</JqxExpander>
)
}
}
ReactDOM.render(<App />, document.getElementById('app'));

Expander API

API Reference of the jQWidgets Expander component for React: Expander API