将CSS样式分配给Slickgrid单元格 [英] Assigning CSS Style to Slickgrid Cells

查看:349
本文介绍了将CSS样式分配给Slickgrid单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Slickgrid是持续发展的,所以对类似问题的一些答案不适用(例如,他们提到不可能为特定单元格分配CSS)。显然现在这是支持,如果有人可以提供使用CSS API的示例在 https: //github.com/mleibman/SlickGrid/wiki/API-Reference

  grid.setCellCssStyles(birthday_highlight ,{
0:{
birthday:highlight,
age:highlight
},

9:{
birthday:highlight,
age:highlight
}
})

我有一个非常简单的网格与AZ列和1-100行:如果单元格的内容是一个数字,我该如何分配黄色背景?



c>(请参阅 https://github.com/mleibman/SlickGrid / wiki / Provide-data-to-the-grid ),但是你必须遍历所有单元格,所以效率不高。也许一个自定义格式化器,看实际价值是一个更好的适合。这样,你将不能为单元格本身指定一个CSS类,但你可以根据你喜欢的样式的单元格内容,所以技术上你可以做一个DIV填充整个单元格,并设置背景


Slickgrid is continuosly evolving so some of the answers to similar issues are not applicable (e.g., they mention it was not possible to assign a CSS to a specific cell). Apparently now this is supported and would appreciate if someone could provide an example using the CSS API at https://github.com/mleibman/SlickGrid/wiki/API-Reference:

grid.setCellCssStyles("birthday_highlight", {
   0: {
        birthday: "highlight", 
        age: "highlight" 
       },

   9: {
         birthday: "highlight",
         age: "highlight"
       }
})

I have a very simple grid with A-Z columns and 1-100 rows: how can I assign a yellow background if the content of the cell is a number?

Thanks

解决方案

This can be done with by implementing getItemMetadata(row) (see https://github.com/mleibman/SlickGrid/wiki/Providing-data-to-the-grid), but you'd have to iterate over all cells, so that's not very efficient. Perhaps a custom formatter that looks at the actual value is a better fit. With that, you won't be able to specify a CSS class for the cell itself, but you'd be able to style the cell content however you like, so technically you could make a DIV that fills the whole cell and set background on that.

这篇关于将CSS样式分配给Slickgrid单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆