Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- Include React & DataGridXL -->
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<script src="https://code.datagridxl.com/datagridxl.js"></script>

<h2>DataGridXL and React</h2>
<h3>Edit cell value(s) to see "data" change</h3>

<div id="app"></div>
              
            
!

CSS

              
                body {
  font-family: sans-serif;
}

#grid {
  height: 400px;
}
              
            
!

JS

              
                // shorthand function to create React elements
var e = React.createElement;

/*----------------------------------

class DataGrid
(wrapper for DataGridXL)

----------------------------------*/

// create a component (wrapper) for DataGridXL
// we name it "DataGrid" since "DataGridXL" already exists.
class DataGrid extends React.Component {

  constructor(props) {
    super(props);
  }

  componentDidMount(){

    // create the Data Grid
    var grid = new DataGridXL("grid");
    
    // save component scope in `self` so we can change our props.
    var self = this;

    // fire the `onChange` property when data changes

    grid.events.on("cellvaluechange", function(ev){
      self.props.onChange.call(this, ev);
    });

    grid.events.on("documentchange", function(ev){
      self.props.onChange.call(this, ev);
    });

    grid.events.on("ready", function(ev){
      self.props.onChange.call(this, ev);
    });

  }

  shouldComponentUpdate(){
    // tell React to not update the DOM for this component
    // DataGridXL fully takes care of this
    return false;
  }

  render() {

    return e(
      'div', {
        id: 'grid'
      }
    );

  }
}

/*----------------------------------

class App

----------------------------------*/

class App extends React.Component {

  constructor(props){

    super(props);

    this.state = {
      data: null
    };
    
    // save App component as window var
    // so we can setState in our handleOnChange method
    window.myApp = this;

  }

  handleOnChange(ev){

    myApp.setState({
      data: JSON.stringify(this.getData())
    });

  }

  render(){
    return e('div', {}, 
      e(DataGrid, {
        onChange: this.handleOnChange
      }),
      e('div', {}, 'data '+this.state.data)
    );
  }

}

// render our App component inside div#app
ReactDOM.render(e(App), document.getElementById("app"));
              
            
!
999px

Console