easyUi表格颜色设置

$(function() {
        $('.btn_state').linkbutton('disable');
    $('#dg').datagrid({
        url : _getPage,
        rownumbers : true,
        pagination : true,
        fitColumns : true,
        fit : true,
        singleSelect : false,
        pageSize : 20,
        pageList : [20, 30, 50],
        remoteSort:true,
        multiSort:true,
        queryParams : {conditions : getSearchConditions()},
        columns : [[
            {field: 'id', title: "id", checkbox:true, hidden: false, width: 100, sortable: true, align: 'center'},
            {field :'serviceCategory',title:'Service Category',hidden:false,width:50,sortable:true,align : 'center',
                //加一个方法(用来设置颜色的)
                styler:rowColor

            },
            {field :'serviceModel',title:'Service Model',hidden:false,width:50,sortable:true,align : 'center'},
            {field :'description',title:'Description',hidden:false,width:50,sortable:true,align : 'center'}
            ]]      
    });
    var pager = $('#dg').datagrid('getPager');
    pager.pagination({
        beforePageText: '第',//页数文本框前显示的汉字 
        afterPageText: '页    共 {pages} 页', 
        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录', 
    });
});

//后台需要的条件
function getSearchConditions(){
    var param = [];
    var filterVal = $("#selectModelSearch").val();
    if(filterVal != null){
        param.push({"name":"dictNameFilter","value":filterVal});
    }
    if(serviceCategory != null){
        param.push({"name":"serviceCategory","value":serviceCategory});
    }
    if(id != null){
        param.push({"name":"id","value":id});
    }

    var conditions =  $.toJSON(param);
    return conditions;  
}
//查询表格数据,添加事件就可以,什么都不需要考虑
function searchGrid() {
    var queryParams = {
        conditions : getSearchConditions()
    };
    $('#dg').datagrid('load', queryParams);
}


//颜色设置
function rowColor(value, row, index) {
    if(row.serviceCategory=='GSM'){
        return 'background-color:red;color:white';
    }

    if(row.serviceCategory=='WCDMA'){
        return 'background-color:cyan;color:white';
    }

    //alert(row.serviceCategory);
 }

你可能感兴趣的:(EasyUi)