Demo - FlexGrid Cell Notes
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.grapecity.com/wijmo/5.latest/styles/wijmo.min.css">
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.min.js"></script>
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.grid.min.js"></script>
<div class="container">
<h1>
Cell Notes
</h1>
<p>
This sample shows how you can add Excel-style cell notes
to FlexGrid controls.</p>
<p>
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.</p>
<div id="theGrid"></div>
</div>
CSS
.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
}
JavaScript
onload = function() {
var tooltip = new wijmo.Tooltip();
new wijmo.grid.FlexGrid('#theGrid', {
showAlternatingRows: false,
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;
wijmo.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!';
...