Cell Notes

This sample shows how you can add Excel-style cell notes to FlexGrid controls. The notes are specified in the data. The formatItem event is used to check if the cell has a note. If it does, the event handler adds a class to the cell element so it displays a note indicator on the upper right corner of the cell and attaches a tooltip to the element.

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import { Tooltip, toggleClass } from '@grapecity/wijmo'; import { FlexGrid } from '@grapecity/wijmo.grid'; document.readyState === 'complete' ? init() : window.onload = init; function init() { var tooltip = new Tooltip(); new FlexGrid('#theGrid', { alternatingRowStep: 0, autoGenerateColumns: false, columns: [ { binding: 'country', header: 'Country' }, { binding: 'downloads', header: 'Downloads', format: 'n0' }, { binding: 'active', header: 'Active' }, { binding: 'sales', header: 'Sales', format: 'n0' }, { binding: 'expenses', header: 'Expenses', format: 'n0' } ], itemsSource: getData(200), // add the wj-has-notes class to cells that have notes and // add a tooltip to the cell element. formatItem: function (s, e) { if (e.panel == s.cells) { var item = s.rows[e.row].dataItem, binding = s.columns[e.col].binding, note = item.notes ? item.notes[binding] : null; toggleClass(e.cell, 'wj-has-notes', note != null); if (note != null) { tooltip.setTooltip(e.cell, '<b>Note:</b><br/>' + note); } } }, // clear all tooltips when updating the view updatingView: function () { tooltip.dispose(); } }); // get some data with notes function getData(cnt) { var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','), data = []; // create the data for (var i = 0; i < cnt; i++) { data.push({ country: countries[i % countries.length], active: i % 5 != 0, downloads: Math.round(Math.random() * 200000), sales: Math.random() * 100000, expenses: Math.random() * 50000 }); } // add some notes for (var i = 0; i < data.length; i++) { var item = data[i], notes = {}; if (item.sales < 5000) { notes.sales = 'What\'s going on in <b>' + item.country + '</b>?'; } if (item.downloads < 20000) { notes.downloads = 'Too few downloads, check adwords...'; } if (item.expenses > 40000) { notes.expenses = 'We\'re spending too much here!'; } if (item.country == countries[0] && !item.active) { notes.country = 'Why isn\'t this active?'; } if (Object.keys(notes).length) { item.notes = notes; } } // done return data; } } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Cell Notes</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <div id="theGrid"></div> </div> </body> </html> .wj-flexgrid { height: 350px; } .wj-cell { border-color: #e0e0e0; } .wj-cell.wj-has-notes:after { position: absolute; content: ''; width: 0; right: 0; top: -10px; border: 10px solid transparent; border-right: 10px solid red; opacity: .5; } .wj-cell.wj-has-notes:hover:after { opacity: 1; } body { margin-bottom: 24pt } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import { Component, enableProdMode, NgModule } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import * as wjcCore from '@grapecity/wijmo'; import * as wjcGrid from '@grapecity/wijmo.grid'; import { WjGridModule } from '@grapecity/wijmo.angular2.grid'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { data: any[]; // DataSvc will be passed by derived classes constructor() { this.data = this._getData(200); } initializeGrid(flex: wjcGrid.FlexGrid) { let tooltip = new wjcCore.Tooltip(); flex.formatItem.addHandler((s: wjcGrid.FlexGrid, e: wjcGrid.FormatItemEventArgs) => { if (e.panel == s.cells) { let item = s.rows[e.row].dataItem, binding = s.columns[e.col].binding, note = item.notes ? item.notes[binding] : null; wjcCore.toggleClass(e.cell, 'wj-has-notes', note != null); if (note != null) { tooltip.setTooltip(e.cell, '<b>Note:</b><br/>' + note); } } }); // clear all tooltips when updating the view flex.updatingView.addHandler(() => { tooltip.dispose(); }); } private _getData(cnt: number) { let countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','), data = []; // create the data for (let i = 0; i < cnt; i++) { data.push({ country: countries[i % countries.length], active: i % 5 != 0, downloads: Math.round(Math.random() * 200000), sales: Math.random() * 100000, expenses: Math.random() * 50000 }); } // add some notes for (let i = 0; i < data.length; i++) { let item: any = data[i], notes: any = {}; if (item.sales < 5000) { notes.sales = 'What\'s going on in <b>' + item.country + '</b>?'; } if (item.downloads < 20000) { notes.downloads = 'Too few downloads, check adwords...'; } if (item.expenses > 40000) { notes.expenses = 'We\'re spending too much here!'; } if (item.country == countries[0] && !item.active) { notes.country = 'Why isn\'t this active?'; } if (Object.keys(notes).length) { item.notes = notes; } } // done return data; } } // @NgModule({ imports: [WjGridModule, BrowserModule], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } // enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Cell Notes</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <wj-flex-grid #flex [alternatingRowStep]="0" (initialized)="initializeGrid(flex)" [(itemsSource)]="data"> <wj-flex-grid-column [binding]="'country'" [header]="'Country'"></wj-flex-grid-column> <wj-flex-grid-column [binding]="'downloads'" [header]="'Downloads'" [format]="'n0'"></wj-flex-grid-column> <wj-flex-grid-column [binding]="'active'" [header]="'Active'"></wj-flex-grid-column> <wj-flex-grid-column [binding]="'sales'" [header]="'Sales'" [format]="'n0'"></wj-flex-grid-column> <wj-flex-grid-column [binding]="'expenses'" [header]="'Expenses'" [format]="'n0'"></wj-flex-grid-column> </wj-flex-grid> </div> .wj-flexgrid { height: 350px; } .wj-cell { border-color: #e0e0e0; } .wj-cell.wj-has-notes:after { position: absolute; content: ''; width: 0; right: 0; top: -10px; border: 10px solid transparent; border-right: 10px solid red; opacity: .5; } .wj-cell.wj-has-notes:hover:after { opacity: 1; } body { margin-bottom: 24pt } <template> <div class="container-fluid"> <wj-flex-grid :alternatingRowStep="0" :initialized="initializeGrid" :itemsSource="data" > <wj-flex-grid-column :binding="'country'" header="'Country'"></wj-flex-grid-column> <wj-flex-grid-column :binding="'downloads'" header="'Downloads'" format="'n0'"></wj-flex-grid-column> <wj-flex-grid-column :binding="'active'" header="'Active'"></wj-flex-grid-column> <wj-flex-grid-column :binding="'sales'" header="'Sales'" format="'n0'"></wj-flex-grid-column> <wj-flex-grid-column :binding="'expenses'" header="'Expenses'" format="'n0'"></wj-flex-grid-column> </wj-flex-grid> </div> </template> <script> import "@grapecity/wijmo.styles/wijmo.css"; import "bootstrap.css"; import Vue from "vue"; import "@grapecity/wijmo.vue2.grid"; import * as wjcCore from "@grapecity/wijmo"; let App = Vue.extend({ name: "app", data: function() { return { data: this._getData(200) }; }, methods: { initializeGrid: function(flex) { let tooltip = new wjcCore.Tooltip(); flex.formatItem.addHandler((s, e) => { if (e.panel == s.cells) { let item = s.rows[e.row].dataItem, binding = s.columns[e.col].binding, note = item.notes ? item.notes[binding] : null; wjcCore.toggleClass(e.cell, "wj-has-notes", note != null); if (note != null) { tooltip.setTooltip(e.cell, "<b>Note:</b><br/>" + note); } } }); // clear all tooltips when updating the view flex.updatingView.addHandler(() => { tooltip.dispose(); }); }, _getData: function(cnt) { let countries = "US,Germany,UK,Japan,Italy,Greece".split(","), data = []; // create the data for (let i = 0; i < cnt; i++) { data.push({ country: countries[i % countries.length], active: i % 5 != 0, downloads: Math.round(Math.random() * 200000), sales: Math.random() * 100000, expenses: Math.random() * 50000 }); } // add some notes for (let i = 0; i < data.length; i++) { let item = data[i], notes = {}; if (item.sales < 5000) { notes.sales = "What's going on in <b>" + item.country + "</b>?"; } if (item.downloads < 20000) { notes.downloads = "Too few downloads, check adwords..."; } if (item.expenses > 40000) { notes.expenses = "We're spending too much here!"; } if (item.country == countries[0] && !item.active) { notes.country = "Why isn't this active?"; } if (Object.keys(notes).length) { item.notes = notes; } } // done return data; } } }); new Vue({ render: h => h(App) }).$mount("#app"); </script> <style> .wj-flexgrid { height: 350px; } .wj-cell { border-color: #e0e0e0; } .wj-cell.wj-has-notes:after { position: absolute; content: ""; width: 0; right: 0; top: -10px; border: 10px solid transparent; border-right: 10px solid red; opacity: 0.5; } .wj-cell.wj-has-notes:hover:after { opacity: 1; } body { margin-bottom: 24pt; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>AutoComplete</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"> </div> </body> </html> import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './app.css'; import * as React from 'react'; import * as ReactDOM from 'react-dom'; import * as wjFlexGrid from '@grapecity/wijmo.react.grid'; import * as wjcCore from '@grapecity/wijmo'; class App extends React.Component { constructor(props) { super(props); this.state = { data: this._getData(200) }; } render() { return <div className="container-fluid"> <wjFlexGrid.FlexGrid alternatingRowStep={0} initialized={this.initializeGrid} itemsSource={this.state.data}> <wjFlexGrid.FlexGridColumn binding="country" header="Country"></wjFlexGrid.FlexGridColumn> <wjFlexGrid.FlexGridColumn binding="downloads" header="Downloads" format="n0"></wjFlexGrid.FlexGridColumn> <wjFlexGrid.FlexGridColumn binding="active" header="Active"></wjFlexGrid.FlexGridColumn> <wjFlexGrid.FlexGridColumn binding="sales" header="Sales" format="n0"></wjFlexGrid.FlexGridColumn> <wjFlexGrid.FlexGridColumn binding="expenses" header="Expenses" format="n0"></wjFlexGrid.FlexGridColumn> </wjFlexGrid.FlexGrid> </div>; } initializeGrid(flex) { let tooltip = new wjcCore.Tooltip(); flex.formatItem.addHandler((s, e) => { if (e.panel == s.cells) { let item = s.rows[e.row].dataItem, binding = s.columns[e.col].binding, note = item.notes ? item.notes[binding] : null; wjcCore.toggleClass(e.cell, 'wj-has-notes', note != null); if (note != null) { tooltip.setTooltip(e.cell, '<b>Note:</b><br/>' + note); } } }); // clear all tooltips when updating the view flex.updatingView.addHandler(() => { tooltip.dispose(); }); } _getData(cnt) { let countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','), data = []; // create the data for (let i = 0; i < cnt; i++) { data.push({ country: countries[i % countries.length], active: i % 5 != 0, downloads: Math.round(Math.random() * 200000), sales: Math.random() * 100000, expenses: Math.random() * 50000 }); } // add some notes for (let i = 0; i < data.length; i++) { let item = data[i], notes = {}; if (item.sales < 5000) { notes.sales = 'What\'s going on in <b>' + item.country + '</b>?'; } if (item.downloads < 20000) { notes.downloads = 'Too few downloads, check adwords...'; } if (item.expenses > 40000) { notes.expenses = 'We\'re spending too much here!'; } if (item.country == countries[0] && !item.active) { notes.country = 'Why isn\'t this active?'; } if (Object.keys(notes).length) { item.notes = notes; } } // done return data; } } ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Cell Notes</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> .wj-flexgrid { height: 350px; } .wj-cell { border-color: #e0e0e0; } .wj-cell.wj-has-notes:after { position: absolute; content: ''; width: 0; right: 0; top: -10px; border: 10px solid transparent; border-right: 10px solid red; opacity: .5; } .wj-cell.wj-has-notes:hover:after { opacity: 1; } body { margin-bottom: 24pt }