Documentation

React UI Components for jQWidgets

React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes.

A. Prerequisites

  • Node.js - to verify that you have it installed, run the command node -v in cmd. It will output the current version.

Note: Make sure that you are running on the latest NodeJS and npm versions.

B. Getting Started

Steps:

  1. Create your project folder structure.
  2. Install and configurate all required modules.
  3. Build and run the app

Step 1 - Create your root project folder

The root folder contains our index.html, a few configuration files, and the app folder which holds the main content of the application.


 /root
    /app
        /app.js
    /index.html
    /package.json
    /webpack.config.js
                        

Note: Structure may vary based on your application needs.

Step 2 - Install and configurate all required modules

First we need to install the React, Webpack and Babel required modules. For that we need a package.json file. Here is ours:

{
"name": "jqwidgets-react-webpack",
"description": "jqwidgets-react-webpack",
"dependencies": {
"react": "15.4.1",
"react-dom": "15.4.1",
"webpack": "1.14.0",
"babel-core": "6.21.0",
"babel-loader": "6.2.10",
"babel-preset-es2015": "6.18.0",
"babel-preset-react": "6.16.0"
},
"scripts": {
"start": "webpack"
},
"author": "www.jQWidgets.com"
}

After your package.json is ready type npm install in your CLI.


Then we need to configure the webpack.config.js file:

var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: {
bargauge: __dirname + '/app/bargauge/app.js'
//You can add additional entry points if you want
//grid: __dirname + '/app/grid/app.js'
},
output: {
path: __dirname + '/build',
filename: '[name].bundle.js'
},
module: {
loaders: [
{
test: /.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['es2015', 'react']
}
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.optimize.UglifyJsPlugin({
mangle: true,
sourcemap: false,
compress: { warnings: false }
})
]
};

Note: Configuration may vary based on your application needs.

Step 3 - Build and run the app

I. Create index.html

Add the needed jQWidgets references:

<!-- jQWidgets Library -->
<link rel="stylesheet" href="jqx.base.css"/>
<script src="jqxcore.js"></script>
<script src="jqxdraw.js"></script>
<script src="jqxbargauge.js"></script>

Add the initialization tag and our app bundle to the body of the index.html.

The app bundle is generated when we type npm start in our CLI.


II. Create Our Component

First we need to add the references for the needed react modules and jQWidgets React files :

import React from 'react';
import ReactDOM from 'react-dom';
import JqxBarGauge from 'jqwidgets-react/react_jqxbargauge.js';

Then we create our widget class. Properties and methods are put as React props.

class App extends React.Component {
render () {
return (
<JqxBarGauge
width={600} height={600} colorScheme={'scheme02'}
max={150} values={[102, 115, 130, 137]}
/>
)
}
}

Then we render our class in the desired HTML element:

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

C. Events Methods & Properties

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

<JqxBarGauge ref='myBarGauge' width={600} height={600}..... />

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

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

I. Events

To bind to an event you must use the following format:

this.refs.widgetReference.on('eventName', (e) => 
{
//your logic
});

For example we want to bind to the jqxBarGauge event drawEnd:


II. Methods & Properties


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


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

D. Example Files

index.html


app.js