Mouse Events

To handle mouse events, add a listener to hostElement of the grid and use the hitTest method to determine which grid panel and cell were clicked.

The grid below has a handler attached to the 'mousemove' event, and shows information about the element that is hovered by the mouse.

please move the mouse over the grid
Id
Country
Product
Active
Downloads
Sales
Expenses
Overdue
Country: US (5 items)
0
US
Phones
145,248
81,732.54
38,401.13
4
US
Phones
126,531
46,951.19
49,107.56
8
US
Phones
139,988
52,628.41
46,700.93
12
US
Phones
6,078
38,100.45
17,157.09
16
US
Phones
29,365
22,131.47
20,503.66
Country: Germany (5 items)
1
Germany
Computers
111,632
20,603.32
27,944.24
5
Germany
Computers
6,073
86,237.02
49,767.35
9
Germany
Computers
137,524
54,681.54
4,055.50
13
Germany
Computers
191,491
50,512.92
35,798.63
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// This file locates: "Scripts/Lesson/C1FlexGrid/EventsMouse.js".
c1.documentReady(function () {
    var theGrid = wijmo.Control.getControl('#theGrid');
 
    // add 'button' to country cells
    theGrid.formatItem.addHandler(function (s, e) {
        if (e.panel == s.cells) {
            if (s.columns[e.col].binding == 'Country') {
                var html = '<span class="my-button">&#x2b24;</span> ' + e.cell.innerHTML;
                e.cell.innerHTML = html;
            }
        }
    });
 
    // monitor and log mouse moves
    var logEl = document.getElementById('log');
    theGrid.addEventListener(theGrid.hostElement, 'mousemove', function (e) {
        var ht = theGrid.hitTest(e);
        var logText = wijmo.format('panel <b>{cellType}</b> row <b>{row}</b> col <b>{col}</b>', {
            cellType: wijmo.grid.CellType[ht.cellType],
            row: ht.row,
            col: ht.col
        });
        if (e.target.classList.contains('my-button')) {
            logText += ' (fake button!)';
        } else if (e.target.tagName == 'INPUT' && e.target.type == 'checkbox') {
            logText += ' (checkbox!)';
        } else if (ht.panel == theGrid.cells) {
            if (theGrid.rows[ht.row] instanceof wijmo.grid.GroupRow) {
                logText += ' (group row)';
            } else {
                logText += ' (value: <b>' + theGrid.cells.getCellData(ht.row, ht.col, true) + '</b>)';
            }
        }
        logEl.innerHTML = logText;
    });
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// This file locates: "Content/css/Lesson/C1FlexGrid/EventsMouse.css".
#log {
  font-style: italic;
  text-align: center;
  margin-bottom: 10px;
  opacity: .5;
}
.my-button {
  opacity: .5;
  margin: 0 6px;
}
.my-button:hover {
  color: orange; 
}
1
2
3
4
5
6
7
8
9
10
11
12
13
using System.Web.Mvc;
 
namespace LearnMvcClient.Controllers
{
    public partial class C1FlexGridController : Controller
    {
        // GET: EventsMouse
        public ActionResult EventsMouse()
        {
            return View(Models.FlexGridData.GetSales(Models.FlexGridData.Countries4, 20));
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@model IEnumerable<FlexGridData.Sale>
 
<h1>
    @Html.Raw(Resources.C1FlexGrid.EventsMouse_Title)
</h1>
<p>
    @Html.Raw(Resources.C1FlexGrid.EventsMouse_Text1)
</p>
<p>
    @Html.Raw(Resources.C1FlexGrid.EventsMouse_Text2)
</p>
<div id="log">
    @Html.Raw(Resources.C1FlexGrid.EventsMouse_Text3)
</div>
@Html.C1().FlexGrid().Id("theGrid").Bind(Model).GroupBy("Country").Height(220)