我在$(document).ready上使用以下行(
$("#stSearchTermsGrid").setCell(2, 2, '', {color:'red'}) ;
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我是以错误的方式写它还是把它放在错误的地方.
我知道这个问题不止一次被问过,这就是我得到第一行的方式.但我仍然无法做到这一点,也不知道问题出在哪里.
我可以通过在jqgrid自定义格式化程序中执行此操作来更改文本颜色:
function YNFormatter(cellvalue, options, rowObject)
{
var color = (cellvalue == "Y") ? "green" : "red";
var cellHtml = "<span style='color:" + color + "' originalValue='" +
cellvalue + "'>" + cellvalue + "</span>";
return cellHtml;
}
Run Code Online (Sandbox Code Playgroud)
但我想现在改变整个单元格的背景颜色(而不是文本颜色).
这可能吗?
我如何才能使jqgrid的所有列都不可调整大小?目前我认为每个列都要指定属性{resizable:false}.无论如何,我可以指定整个网格吗?
我猜是afterInsertRow是要使用的方法,我已经为每一行(读/未读)提供了额外的数据,使用了键"readStatus".
我不想要的是在网格完成后横向移动DOM,根据某个单元格值将行添加到行中.
有什么建议?
添加在:
如果这是单元格数据:
{"cell":["blah blah blah"],"id":"123456789","readstatus":"unread"}
Run Code Online (Sandbox Code Playgroud)
我如何进入'readstatus'部分?
我有一个相当复杂的网格,其中两列格式化为复选框.这些列定义如下:
{ name: 'Alert_A', index: 'Alert_A', width: 22, align: 'center', sortable: false,
formatter: CheckBoxFormatter, editable: true, edittype: 'checkbox', editoptions: {value: "True:False"},
formatoptions: {disabled: false}, classes: "Alert_A" },
{ name: 'Alert_B', index: 'Alert_B', width: 22, align: 'center', sortable: false,
formatter: CheckBoxFormatter, editable: true, edittype: 'checkbox', editoptions: { value: "True:False" },
formatoptions: {disabled: false}, classes: "Alert_B" }
Run Code Online (Sandbox Code Playgroud)
CheckBoxFormatter需要自定义格式化程序,因为我需要根据一些自定义规则设置每个复选框的disabled属性,因此我借用了原生的"复选框"格式化程序并添加了我的自定义规则.
我还有一个外部的html按钮元素,当我点击它时,我需要执行一些代码,具体取决于复选框选择的组合.我的代码看起来像这样:
$('#btnAlert').button().click(function (event) {
event.preventDefault();
var dashboardID = '#<%=dashboard.ClientID %>';
doWork(dashboardID);
});
Run Code Online (Sandbox Code Playgroud)
以及后来的doWork功能
var keys = $(dashboardID).getDataIDs();
for (var i = …Run Code Online (Sandbox Code Playgroud) 我的jqgrid中有一个coulmn状态.
如果状态为"活动",则我希望同一行中的另一个单元格为绿色.如果状态为"未激活",我希望单元格为红色.
如何才能做到这一点?
截至目前,我已在"图片"行创建了自定义格式化程序:
formatter: function () { return "<img src='../images/red.png'/>" }
Run Code Online (Sandbox Code Playgroud) 我已经看到有关条件格式的大量信息,但似乎无法让它工作.我希望当它的值(即日期)过去时,将单元格的字体设置为红色.
这是我现在所拥有的一般概念:
{
name: 'IsoDate', index: 'IsoDate', align: 'left', sorttype: 'date', datefmt: "m/d/Y",
formatter: function (cellvalue, options, rowobject) { var now = new Date(); if (cellvalue < now) { return '<span class="error">' + cellvalue + '</span>'; } else { cellvalue; } }
}
Run Code Online (Sandbox Code Playgroud)
我似乎无法让它工作.我已经得到它来返回所有红色值或所有未定义的值.有些领域还没有日期.
我很感激任何帮助!谢谢!
更新:
这是我使用的代码,最终工作.我实际上是在引用日期的另一列.
cellattr: function (rowid, val, rawObject, cm, rdata) {
var idate = new Date(rawObject['IsoDate']);
return (idate < new Date()) ? ' class = "ui-state-error-text"' : ' class = "field-validation-green"';
}
Run Code Online (Sandbox Code Playgroud)