Run the examples on your computer
You can copy the code on an example page and use it as is. Where it runs depends on the framework. Pick your way in the table below.
| You use | Where it runs | Time |
|---|---|---|
| JavaScript | Edit and run it right away with Try it (the playground) on the example page. No setup. | 1 minute |
| One HTML file | Save the code as index.html and open it in a browser. No setup. | 1 minute |
| React | Create a project on your computer and run it there. | About 10 min |
| Vue | Create a project on your computer and run it there. | About 10 min |
| Angular | Create a project on your computer and run it there. | About 15 min |
React, Vue and Angular need a build tool that turns the code into something a browser can read. That is why the playground does not run them. Set a project up once with the steps below, and after that you only copy an example into its files.
Open in an online editor
Each code tab of a gallery example page (JavaScript, React, Vue, Angular) has Open in StackBlitz and Open in CodeSandbox buttons. Pressing one opens a runnable project of that tab in a new browser tab.
- The project has a
package.json; MaxGrid packages are pinned to the exact released version, and@maxgrid/themes/grid.cssis imported. - The first start takes about a minute to install packages; edits show up right away.
- Nothing is sent before you press a button. When you do, the example code is sent to that service (the same note sits under the buttons).
- Offline, the page shows how to run the example on your own computer instead.
What you need
Node.js
You need it to create React, Vue and Angular projects. Download the LTS (stable) version from the official site and install it.
- Download: nodejs.org/en/download
- When it finishes, open a new terminal (PowerShell on Windows, Terminal on Mac) and check.
node -v
npm -vIf both print a version number, you are ready. Node.js 20 or later is recommended.
A code editor
An editor helps because you handle several files. This one is free and the most common.
- Download: code.visualstudio.com
JavaScript and one HTML file
- Open the HTML tab on the example page and press the copy button on the code block.
- Paste it into a text editor and save it as
index.html. - Double-click
index.htmland the grid appears in your browser.
You need an internet connection because the grid file is loaded from this site. To see a change, refresh the browser.
Good to know when saving the file
- Windows Notepad: in the save dialog, set the file type to
All filesand name itindex.html. Otherwise it is saved asindex.html.txtand will not open. - Get it from the playground: the
Save as HTML filebutton in the playground downloads your edited code as an.htmlfile. - Internet connection: the grid file is loaded from this site, so you need to be online. An ad-blocking extension that blocks the address can leave the page blank.
- If the page is blank: press
F12in the browser and look for red errors in theConsoletab. The message tells you the cause.
If you want to experiment, Try it at the top right of the example page is the fastest way. Change the code in the playground and press Ctrl+Enter (⌘+Enter on Mac) to see it right away.
React
The React tab of an example has two files: ExampleGrid.tsx (connects the grid) and example.ts (the data and options).
1. Create the project
In a terminal, go to the folder where you want the project and run these in order. Press Enter to accept the default answers.
npm create vite@latest my-grid -- --template react-ts
cd my-grid
npm install2. Install MaxGrid
npm install @maxgrid/react @maxgrid/themes3. Add the files
- Save the example's
example.tsassrc/example.ts. - Save the example's
ExampleGrid.tsxassrc/ExampleGrid.tsx. - Open
src/main.tsx, load the theme CSS and renderExampleGrid.
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import '@maxgrid/themes/grid.css';
import { ExampleGrid } from './ExampleGrid';
createRoot(document.getElementById('root')!).render(
<StrictMode>
<ExampleGrid />
</StrictMode>,
);4. Run
npm run devOpen the address the terminal prints (usually http://localhost:5173) in a browser. If the grid appears, it worked. Press Ctrl+C in the terminal to stop.
Vue
The Vue tab has ExampleGrid.vue and example.ts.
1. Create the project
npm create vite@latest my-grid -- --template vue-ts
cd my-grid
npm install2. Install MaxGrid
npm install @maxgrid/vue @maxgrid/themes3. Add the files
- Save the example's
example.tsassrc/example.ts. - Save the example's
ExampleGrid.vueassrc/ExampleGrid.vue. - Add one line for the theme CSS to
src/main.ts, and useExampleGridinsrc/App.vue.
// src/main.ts
import { createApp } from 'vue';
import '@maxgrid/themes/grid.css';
import App from './App.vue';
createApp(App).mount('#app');<!-- src/App.vue -->
<script setup lang="ts">
import ExampleGrid from './ExampleGrid.vue';
</script>
<template>
<ExampleGrid />
</template>4. Run
npm run devOpen the address the terminal prints (usually http://localhost:5173) in a browser.
Angular
The Angular tab has example-grid.component.ts and example.ts.
1. Create the project
If you use npx, you do not have to install the Angular CLI separately. When it asks, choose CSS for the stylesheet format and No for server-side rendering (SSR).
npx @angular/cli new my-grid
cd my-grid2. Install MaxGrid
npm install @maxgrid/angular @maxgrid/themes3. Add the files
- Save the example's
example.tsassrc/app/example.ts. - Save the example's
example-grid.component.tsassrc/app/example-grid.component.ts. - Load the theme CSS at the top of
src/styles.css. - Change
src/app/app.component.ts(orapp.ts) as below.
/* src/styles.css */
@import '@maxgrid/themes/grid.css';// src/app/app.component.ts
import { Component } from '@angular/core';
import { ExampleGridComponent } from './example-grid.component';
@Component({
selector: 'app-root',
standalone: true,
imports: [ExampleGridComponent],
template: '<app-example-grid />',
})
export class AppComponent {}4. Run
npm startOpen the address the terminal prints (usually http://localhost:4200) in a browser.
If something does not work
- The grid does not show. The grid fills the height of its parent. The example code sets a height, so check that no line is missing. Getting started has the details.
- You get a
Cannot find moduleerror. Check that you saved each file under the right name insrcand ran the install command. - An option from the example has no effect. The installed package may be older than the example. Update it to the latest (for React,
npm install @maxgrid/react@latest; Vue and Angular work the same way). - There is no styling at all. Check that the line loading the theme CSS is there.
For more, continue with the Framework guide.