Web/javascript / jQuery
[jQuery] SlickGrid 에서 각 행을 루프돌면서 상태에 따른 색상 세팅하기
RAY.D
2015. 4. 13. 23:36
SlickGrid 에서 각 행을 루프돌면서 상태에 따른 색상 세팅하기
SlickGrid: How to loop through each row and set color based on the condition?
Assuming you're using Slick.Data.DataView
, you can modify the getItemMetadata
method to dynamically add classes to the containing row element. I am going to write this as if your Slick.Data.DataView
instance is called dataView
, here you go:
dataView.getItemMetadata = metadata(dataView.getItemMetadata);
function metadata(old_metadata_provider) {
return function(row) {
var item = this.getItem(row);
var ret = (old_metadata_provider(row) || {});
if (item) {
ret.cssClasses = (ret.cssClasses || '');
if (item.age >= 20 && item.age <= 40) {
ret.cssClasses += ' blue';
} else {
ret.cssClasses += ' red';
}
}
return ret;
}
}
This will add a class of 'blue'
or 'red'
to the row's element.
http://stackoverflow.com/questions/19496846/slickgrid-how-to-loop-through-each-row-and-set-color-based-on-the-condition