[jQuery] SlickGrid 에서 각 행을 루프돌면서 상태에 따른 색상 세팅하기

Posted by RAY.D
2015. 4. 13. 23:36 Web/javascript / jQuery
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.




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