# easyui 按条件设置行背景色

**URL:** <https://www.shiqidu.com/t/topic/216>\
**Category:** 开发调优\
**Tags:** JavaScript\
**Created:** [2017 年8 月 24 日 07:29 UTC](https://www.shiqidu.com/t/topic/216 "2017-08-24T07:29:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![Leon](https://www.shiqidu.com/user_avatar/www.shiqidu.com/leon/32/5_2.png) [@Leon](https://www.shiqidu.com/u/Leon)\
发布日期： [2017 年8 月 24 日 07:29 UTC](https://www.shiqidu.com/t/topic/216/1 "2017-08-24T07:29:38Z")

</div>

周六日的数据希望给一个特殊的背景色区分

```javascript
$('#dg').datagrid({
            title: '设置行背景色',
            url: '/xxx.php',
            pagination: false,//显示分页
            singleSelect: true,
            height : 'auto',
            iconCls: "icon-large-shapes",//图标
            showFooter: true,
            rownumbers: true,
            fitColumns:true,
            columns: [[
                {field: 'rate', width:100, title: '比例', sortable: true, formatter: formatter_rate},
                /*...*/
            ]],
            /* 周六日的数据设置蓝色背景色
            * 如果是周六日我后台返回的date字段是这样的 2017-08-19 [六]
            */
            rowStyler:function(index,row){
                if (/[六|日]/.test(row.date)){
                    return 'background-color:#e5efff;';
                }
            }
        });

```
