在这次做项目中,就此问题,花费了我大半天时间,一度差点放弃,但作为后端开发人员,遇到难题怎能不攻克?贴出代码以供大家参考
先来一个style
<style>
.redClass {
background-color: pink;
color: blue;
font-weight: bold;
}
</style>
然后我们来一个全局数据
var rowIndexArr = [];
然后我们在datagrid 的rowStyler中这么写
rowStyler: function (index, row) {
if (row.xxx != "是") {
//return 'background-color:pink;color:blue;font-weight:bold;';
return {class: 'redClass'}
} else {
rowIndexArr.push(index);
}
},
然后在datagrid的onSelect中这么写
onSelect: function (index, row) {
var opt = $(this).datagrid("options");
var rows1 = opt.finder.getTr(this, "", "allbody", 1);
var rows2 = opt.finder.getTr(this, "", "allbody", 2);
if (rows1.length > 0) {
$(rows1).each(function () {
var tempIndex = parseInt($(this).attr("datagrid-row-index"));
if (tempIndex == index) {
$(this).removeClass("redClass");
} else {
var findIndex = $.inArray(tempIndex, rowIndexArr);
if (findIndex == -1) {
$(this).addClass("redClass");
}
}
});
}
if (rows2.length > 0) {
$(rows2).each(function () {
var tempIndex = parseInt($(this).attr("datagrid-row-index"));
if (tempIndex == index) {
$(this).removeClass("redClass");
} else {
var findIndex = $.inArray(tempIndex, rowIndexArr);
if (findIndex == -1) {
$(this).addClass("redClass");
}
}
});
}
}
然后就搞定啦,改变思路,其实一切就会变得很简单