7a3f3dc Oct 13, 2013
@mleibman @milang @tobya
142 lines (126 sloc) 3.83 KB
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SlickGrid example 7: Events</title>
<link rel="stylesheet" href="../slick.grid.css" type="text/css"/>
<link rel="stylesheet" href="../css/smoothness/jquery-ui-1.8.16.custom.css" type="text/css"/>
<link rel="stylesheet" href="examples.css" type="text/css"/>
.cell-title {
font-weight: bold;
#contextMenu {
background: #e1efc7;
border: 1px solid gray;
padding: 2px;
display: inline-block;
min-width: 100px;
-moz-box-shadow: 2px 2px 2px silver;
-webkit-box-shadow: 2px 2px 2px silver;
z-index: 99999;
#contextMenu li {
padding: 4px 4px 4px 14px;
list-style: none;
cursor: pointer;
background: url("../images/arrow_right_peppermint.png") no-repeat center left;
#contextMenu li:hover {
background-color: white;
<table width="100%">
<td valign="top" width="50%">
<div id="myGrid" style="width:600px;height:500px;"></div>
<td valign="top">
<li>handling events from the grid:</li>
<li>Right-click the row to open the context menu</li>
<li>Click the priority cell to toggle values</li>
<h2>View Source:</h2>
<li><A href="https://github.com/mleibman/SlickGrid/blob/gh-pages/examples/example7-events.html" target="_sourcewindow"> View the source for this example on Github</a></li>
<ul id="contextMenu" style="display:none;position:absolute">
<b>Set priority:</b>
<li data="Low">Low</li>
<li data="Medium">Medium</li>
<li data="High">High</li>
<script src="../lib/firebugx.js"></script>
<script src="../lib/jquery-1.7.min.js"></script>
<script src="../lib/jquery-ui-1.8.16.custom.min.js"></script>
<script src="../lib/jquery.event.drag-2.2.js"></script>
<script src="../slick.core.js"></script>
<script src="../slick.editors.js"></script>
<script src="../slick.grid.js"></script>
var grid;
var data = [];
var columns = [
{id: "title", name: "Title", field: "title", width: 200, cssClass: "cell-title", editor: Slick.Editors.Text},
{id: "priority", name: "Priority", field: "priority", width: 80, selectable: false, resizable: false}
var options = {
editable: true,
enableAddRow: false,
enableCellNavigation: true,
asyncEditorLoading: false,
rowHeight: 30
$(function () {
for (var i = 0; i < 100; i++) {
var d = (data[i] = {});
d["title"] = "Task " + i;
d["priority"] = "Medium";
grid = new Slick.Grid("#myGrid", data, columns, options);
grid.onContextMenu.subscribe(function (e) {
var cell = grid.getCellFromEvent(e);
.data("row", cell.row)
.css("top", e.pageY)
.css("left", e.pageX)
$("body").one("click", function () {
grid.onClick.subscribe(function (e) {
var cell = grid.getCellFromEvent(e);
if (grid.getColumns()[cell.cell].id == "priority") {
if (!grid.getEditorLock().commitCurrentEdit()) {
var states = { "Low": "Medium", "Medium": "High", "High": "Low" };
data[cell.row].priority = states[data[cell.row].priority];
$("#contextMenu").click(function (e) {
if (!$(e.target).is("li")) {
if (!grid.getEditorLock().commitCurrentEdit()) {
var row = $(this).data("row");
data[row].priority = $(e.target).attr("data");