1.在页面中加样式

<style type="text/css">
.SelectBG{
background-color:#AAAAAA;
}
</style>

2.在js中

  gridComplete:function(){
var ids = $("#gridTable").getDataIDs();
for(var i=0;i<ids.length;i++){
var rowData = $("#gridTable").getRowData(ids[i]);
if(rowData.overdueDays==0){//如果天数等于0,则背景色置灰显示
$('#'+ids[i]).find("td").addClass("SelectBG");
}
}
}

案例:

 shrinkToFit: true,//此属性用来说明当初始化列宽度时候的计算类型,如果为ture,则按比例初始化列宽度。如果为false,则列宽度使用colModel指定的宽度
 multiselect: true, multiboxonly: true,//只有当multiselect = true.起作用,当multiboxonly 为ture时只有选择checkbox才会起作用
gridComplete: function () {
var ids = $("#gridTable").getDataIDs();
for (var i = 0; i < ids.length; i++) {
var rowData = $("#gridTable").getRowData(ids[i]);
if (rowData.Audit == "不通过") {//如果审核不通过,则背景色置于红色
$('#' + ids[i]).find("td").addClass("SelectBG");
}
} $("#" + this.id).jqGrid('setSelection', SelectRowIndx);
}
    //加载表格
function GetGrid() {
var SelectRowIndx;
$("#gridTable").jqGrid({
url: "@Url.Content("~/School/SitesDetails/GridPageListJson")",
datatype: "json",
height: $(window).height() - 178,
autowidth: true,
colModel: [
{ label: '主键', name: 'Id', index: "Id", hidden: true, key: true,},
{ label: '所属栏目', name: 'Name', index: "Name", width: 100 },
{ label: '标题名称', name: 'Title', index: "Title", width: 320 },
//{label:'文章来源',name:'origin',index:'origin',width:100},
{
label: '置顶', name: 'IsTop', index: 'IsTop', width: 80
,
formatter: function (cellvalue, options, rowObject) {
if (cellvalue == true) return "是";
if (cellvalue == false) return "否";
}
},
{ label: '点击量', name: 'Hits', index: 'Hits', width: 80 },
{
label: '允许评论', name: 'IsComment', index: 'IsComment', width: 80
,
formatter: function (cellvalue, options, rowObject) {
if (cellvalue == true) return "是";
if (cellvalue == false) return "否";
}
},
{
label: '审核', name: 'Audit', index: 'Audit', width: 80
,
formatter: function (cellvalue, options, rowObject) {
if (cellvalue == "1") return "<font color='blue'>等待审核</font>";
if (cellvalue == "2") return "<font color='green'>通过审核</font>";
//if (cellvalue == "3") return "<font color='red'>不通过</font>";
if (cellvalue == "3") return "不通过";
}
},
{ label: '文章标签', name: 'ArticleFlag', index: 'ArticleFlag', width: 80 },
{ label: '创建者', name: 'CreateUserName', index: 'CreateUserName', width: 80 },
{
label: '创建日期', name: 'CreateDate', index: 'CreateDate', width: 120,
formatter: function (cellvalue, options, rowObject) {
return formatDate(cellvalue, 'yyyy-MM-dd hh:mm');
}
},
{ label: '修改者', name: 'ModifyUserName', index: 'ModifyUserName', width: 80 },
{
label: '修改日期', name: 'ModifyDate', index: 'ModifyDate', width: 120,
formatter: function (cellvalue, options, rowObject) {
return formatDate(cellvalue, 'yyyy-MM-dd hh:mm');
}
},
{ label: '审核人', name: 'AuditUserName', index: 'AuditUserName', width: 80 },
{
label: '审核日期', name: 'AuditDate', index: 'AuditDate', width: 120,
formatter: function (cellvalue, options, rowObject) {
return formatDate(cellvalue, 'yyyy-MM-dd hh:mm');
}
}
],
viewrecords: true,
rowNum: 30,
rowList: [30, 50, 100, 500, 1000],
pager: "#gridPager",
sortname: 'CreateDate',
sortorder: 'Desc',
rownumbers: true,
shrinkToFit: true,//此属性用来说明当初始化列宽度时候的计算类型,如果为ture,则按比例初始化列宽度。如果为false,则列宽度使用colModel指定的宽度
multiselect: true,
multiboxonly: true,//只有当multiselect = true.起作用,当multiboxonly 为ture时只有选择checkbox才会起作用
ondblClickRow: function (rowid) {
var KeyValue = rowid;
if (IsChecked(KeyValue)) {
var url = "/School/SitesDetails/Form?KeyValue=" + KeyValue;
openDialog(url, "Form", "编辑文章", 900, 450, function (iframe) {
top.frames[iframe].AcceptClick();
});
}
},
onSelectRow: function () {
SelectRowIndx = GetJqGridRowIndx("#" + this.id);
},
gridComplete: function () {
var ids = $("#gridTable").getDataIDs();
for (var i = 0; i < ids.length; i++) {
var rowData = $("#gridTable").getRowData(ids[i]);
if (rowData.Audit == "不通过") {//如果审核不通过,则背景色置于红色
$('#' + ids[i]).find("td").addClass("SelectBG");
}
} $("#" + this.id).jqGrid('setSelection', SelectRowIndx);
}
});
columnModelData("#gridTable");
//自应高度
$(window).resize(function () {
$("#gridTable").setGridHeight($(window).height() - 178);
});
}

效果图如下:

jqGrid设置指定行的背景色的更多相关文章

  1. 原创:如何实现在Excel通过循环语句设置指定行的格式

    原创:如何实现在Excel通过循环语句设置指定行的格式 一.需求: 想让excel的某些行(比如3的倍数的行)字体变成5号字 如何整: 二.实现: Sub code() To Range(" ...

  2. DevExpress.XtraGrid.Views 设置指定行的背景颜色 .

    如需要将指定行的背景设置颜色,可参考以下示例 1.事件:CustomDrawCell 2.示例: private void gridView1_CustomDrawCell(object sender ...

  3. 使用layui框架根据字段来设置tr行的背景色

    问题来源:最近在写公司项目时使用layui遇见的问题,老板要求根据td字段来设置整行tr的背景色. 解决:一开始数据比较少的时候只是直接在页面根据js动态判断字段然后来更改背景色,结果能够成功,但是后 ...

  4. JQuery EasyUI DataGrid根据条件设置表格行样式(背景色)

    1.javascript定义函数返回样式 <script type="text/javascript"> //根据条件设置表格行背景颜色 function setRow ...

  5. 设置datalist指定行的背景色

    前台: <div class="table-responsive" > <table class="table table-bordered table ...

  6. jqgrid 设置编辑行中的某列为下拉选择项

    有时,需要对编辑行中的某列的内容通过选择来完成,以保证数据的一致性.规范性. 可设置colModel的label的属性 edittype: "select",同时指定 editop ...

  7. Android Material适配 为控件设置指定背景色和点击波纹效果

    Android Material适配 为控件设置指定背景色和点击波纹效果,有需要的朋友可以参考下. 大部分时候,我们都需要为控件设置指定背景色和点击效果 4.x以下可以使用selector,5.0以上 ...

  8. WPF ListView控件设置奇偶行背景色交替变换以及ListViewItem鼠标悬停动画

    原文:WPF ListView控件设置奇偶行背景色交替变换以及ListViewItem鼠标悬停动画 利用WPF的ListView控件实现类似于Winform中DataGrid行背景色交替变换的效果,同 ...

  9. 设置listContrl中指定行的颜色

    在MFC中 自己通过手动拖放CListCtrl控件来制作自己的表格: 目的: 将指定item的行更该颜色: 步骤: 1,在窗口中拖放CListCtrl控件, 单击右键 创建控件对象: CListCtr ...

随机推荐

  1. Qt里获取目录的一个另类方法

    如果有一个文件的全路径文件名, 想获取它的路径的话, qt里我没找到比较好的办法, 都是cleanPath后, 再用QString的find, left这种函数来处理. 今天又在搞这种问题的时候, 看 ...

  2. NAT概述

    引言 私有IP是无法在因特网上使用的,而如今普遍使用的宽带网络(ADSL)最多所能提供给用户的IP为16个,最少则为一个,万一企业内部有50台计算机要同时连接上因特网,该如何解决呢?这个问题的正确解决 ...

  3. [IOS] 利用@IBInspectable

    某些uiview中设置 这个关键字 IBInspectable 可以让其设置的属性,在右侧的属性栏目里面进行直接设置, 这是最近看了一下wwdc的一个视频学习到的,可以方便的进行 UI的测试,

  4. Java中线程的生命周期

    首先简单的介绍一下线程: 进程:正在运行中的程序.其实进程就是一个应用程序运行时的内存分配空间. 线程:其实就是进程中的一条执行路径.进程负责的是应用程序的空间的标示.线程负责的是应用程序的执行顺序. ...

  5. 二进制mysql5.7.16下载地址

    下载地址:http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz 2. 解压 tar  xx ...

  6. 《实战Java虚拟机》,最简单的JVM入门书,京东活动,满200就减100了,该出手了

    #京东满200—100单# 图书放血大卖了 <实战Java虚拟机>http://item.jd.com/11670385.html 参加京东满200减 100的大促,就在6.1这一天,仅此 ...

  7. mysql performance_schema 和information_schema.tables了解

    这个是关于mysql的系统表,性能表,核心表操作的一些介绍,深入算不上 我们一般很少去动 mysql  information_schema 信息相关  performance_schema 性能相关 ...

  8. windows中查看开机时间

    windows中查看开机时间     在windows下可以使用systeminfo命令来查看. 下面是网站摘录的关于windows启动了多长时间的内容 1. windows系统可以查看从开机到现在共 ...

  9. track message forwards, avoiding request loops, and identifying the protocol capabilities of all senders along the request/response chain

    https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html The TRACE method is used to invoke a remote, ...

  10. jQuery 实时监听<input>输入值的变化

    这方法比 on('keydown') 更实时 <input type='text' id='input1'/>$(document).ready(function(){ $('#input ...