Styling over class names
by FancyGrid Inc.
HTML
<script src="https://cdn.jsdelivr.net/npm/fancygrid/client/fancy.min.js"></script>
<div id="container" style="width: 700px; height: 800px;"></div>
CSS
.red.fancy-grid-cell {
background-color: rgba(228, 107, 103, 0.4) !important; /* RED */
}
.green.fancy-grid-cell {
background-color: rgba(101, 174, 110, 0.4) !important; /* GREEN */
}
.yellow.fancy-grid-cell {
background-color: rgba(255, 219, 88, 0.5) !important; /* YELLOW */
}
JavaScript
document.addEventListener("DOMContentLoaded", function() {
new FancyGrid({
renderTo: 'container',
data: data,
selModel: 'row',
trackOver: true,
theme: 'extra-gray',
defaults: {
resizable: true,
sortable: true,
draggable: true,
width: 95,
align: 'center',
cellAlign: 'center'
},
cellStylingCls: ['green', 'red', 'yellow'],
columns: [{
type: 'order'
}, {
index: 'brand',
title: 'Brand'
}, {
index: 'model',
title: 'Model'
}, {
index: 'engine',
title: 'Engine',
render: function(o){
if(o.value < 2){
o.cls = 'red';
}
else if(o.value >= 2 && o.value < 3){
o.cls = 'yellow';
}
else if(o.value >= 3){
o.cls = 'green';
}
return o;
}
}, {
index: 'transmission',
title: 'Transmission'
}, {
index: 'hp',
title: 'HP'
}, {
index: 'fuel',
title: 'Fuel'
}, {
index: 'drive',
title: 'Drive'
}, {
index: 'manufactured',
title: 'Manufactured'
}, {
index: 'color',
title: 'Shade'
}, {
index: 'price',
title: 'Price',
type: 'currency'
}]
});
});
var data = [{
brand: 'KIA',
model: 'Sorento',
drive: '4WD',
transmission: 'Auto',
engine: '2.2',
hp: 200,
fuel: 'Diesel',
price: 35000,
manufactured: 'South Korea',
color: 'Gray'
},
{
brand: 'KIA',
model: 'Sorento',
drive: '4WD',
transmission: 'Auto',
engine: '2.4',
hp: 188,
fuel: 'Petrol',
price: 33000,
manufactured: 'South Korea',
color: 'Gray'
},
{
brand: 'KIA',
model: 'Sportage',
drive: '2WD',
transmission: 'Manual',
engine: '2.0',
hp: 150,
fuel: 'Petrol',
price: 20000,
manufactured: 'South Korea',
color: 'White'
},
{
brand: 'KIA',
model: 'Sportage',
...