var grid;
var post_format_timeout;
var post_format_cells = [];
function highlight_completion(grid, row, cell, value, cellNode) {
var $c = $(cellNode);
if (value <= 25)
col = #ff8080 ;
else if (value >= 75)
col = #80ff80 ;
else
col = #ffff80 ;
$c.css( background-color , col);
}
function post_format() {
var n = post_format_cells.length;
for (var i=0; i<n; ++i) {
var info = post_format_cells[i];
var grid = info[0];
var row = info[1];
var cell = info[2];
var value = info[3];
var highlight_fn = info[4];
var cellNode = grid.getCellNode(row, cell);
highlight_fn(grid, row, cell, value, cellNode);
}
post_format_timeout = null;
post_format_cells = [];
}
function post_format_push(info) {
if (!post_format_timeout) {
post_format_timeout = setTimeout(post_format, 0);
post_format_cells = [];
}
post_format_cells.push(info);
}
function format_completion(grid, row, cell, value, colDef, dataContext) {
post_format_push([grid, row, cell, value, highlight_completion]);
return grid.getOptions().defaultFormatter(row, cell, value, colDef, dataContext);
}
$(function () {
var data = [];
for (var i = 0; i < 500; i++) {
data[i] = {
title: "Task " + i,
duration: "5 days",
percentComplete: Math.round(Math.random() * 100),
start: "01/01/2009",
finish: "01/05/2009",
effortDriven: (i % 5 == 0)
};
}
var my_format_completion = function(row, cell, value, colDef, dataContext) {
return format_completion(grid, row, cell, value, colDef, dataContext);
}
var columns = [
{id: "title", name: "Title", field: "title"},
{id: "duration", name: "Duration", field: "duration"},
{id: "%", name: "% Complete", field: "percentComplete", formatter: my_format_completion},
{id: "start", name: "Start", field: "start"},
{id: "finish", name: "Finish", field: "finish"},
{id: "effort-driven", name: "Effort Driven", field: "effortDriven"}
];
var options = {
enableCellNavigation: true,
enableColumnReorder: false,
explicitInitialization: true
};
grid = new Slick.Grid("#myGrid", data, columns, options);
grid.init();
});
<link rel="stylesheet" href="https://cdn.rawgit.com/6pac/SlickGrid/2.2.6/slick.grid.css" type="text/css"/>
<link rel="stylesheet" href="https://cdn.rawgit.com/6pac/SlickGrid/2.2.6/css/smoothness/jquery-ui-1.11.3.custom.css" type="text/css"/>
<link rel="stylesheet" href="https://cdn.rawgit.com/6pac/SlickGrid/2.2.6/examples/examples.css" type="text/css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/6pac/SlickGrid/2.2.6/lib/jquery.event.drag-2.2.js"></script>
<script src="https://cdn.rawgit.com/6pac/SlickGrid/2.2.6/slick.core.js"></script>
<script src="https://cdn.rawgit.com/6pac/SlickGrid/2.2.6/slick.grid.js"></script>
<div id="myGrid" style="width:500px; height:180px;"></div>