简体   繁体   English

我如何在 jqgrid colmodel 中写入条件

[英]How can i write condition in jqgrid colmodel

Can u help me.你能帮我吗。 I have the following colmodel:我有以下colmodel:

 colNames: ["Name","Value", "upper limit", "lower limit", "stock"], colModel: [ { name: 'Num', index:'num', align:"center", sortable:false,width: 40, resizable:false }, { name: 'Value', index:'Value', align:"center", width: 70, cellattr: function (rowId, cellValue, rawObject, cm, rdata) { // { // if (rawObject[1] >= 300 || rawObject[1] <= 50) { // var colorText = 'style="font-weight: bold;font-size: 24px;+colorText"'; // } else { // var colorText = 'style="font-weight: bold;font-size: 24px;color:red"'; // }; return(colorText);}}, console.log (rawObject[1]) }}, {name:'upper', index:'upper', align:"center", width: 25, resizable:false,editable:true, cellattr: function(rowId, val, rawObject){return 'style="font-size: 15px;"';}}, {name:'lower', index:'lower', align:"center", width: 25, resizable:false, editable:true, cellattr: function(rowId, val, rawObject){return 'style="font-size: 15px;"';}}, { name: 'stock', index:'stock', align:"center", sortable:false,width: 40, resizable:false } ],

Below is what I get from get-data.php.以下是我从 get-data.php 得到的信息。

$array = array(
array("1","$f1rst", "300","50"),//: Закладочный ствол
array("2","$second","350","60"),//: Клетьевой ствол
array("3","$three","120","20"),//: Портал
array("4","$four","200","20"),//: Скиповой ствол
array("5","$five","200","0"));//: ЦВС


//var_dump($array);
if (empty($array)) {
    echo '["Нет данных"]';
}
else {echo json_encode($array);}

index.php example index.php 示例

I need to compare values.我需要比较值。 For example: there is the first value in the first cell equal to 60. If 'value'> = 300 or 'value' <= 50, then paint the cell red.例如:第一个单元格中的第一个值等于 60。如果 'value'> = 300 或 'value' <= 50,则将单元格涂成红色。 Next, the second cell.接下来,第二个单元格。 If value> = 350 or value <= 60. And so with all five meanings.如果 value> = 350 或 value <= 60。因此具有所有五种含义。

upd.更新。 In my example, the code doesn't work.在我的示例中,代码不起作用。 It does a conditional check on the entire column.它对整个列进行条件检查。 And I need for each cell我需要每个单元格

upd2.更新2。 see how it works看看它怎么运作在此处输入图像描述

Tony Tomov gave the correct answer.托尼托莫夫给出了正确的答案。 Thank you very much, everything worked out and everything works非常感谢,一切顺利,一切正常

Below is a link to an example下面是一个示例的链接

example例子

 {label: 'Название', name: 'Num', index: 'num', align: "center", sortable: false, width: 40, resizable: false},
        {
          label: 'Значение', name: 'Value', index: 'Value', align: "center", width: 70,
          cellattr: function (rowId, cellValue, rawObject, cm, rdata) {
            if (rdata["Num"] === '1' && (rdata['Value'] >= 300 || rdata['Value'] <= 50)) {
              return ' class="class1" ';
            } else if (rdata["Num"] === '2' && (rdata['Value'] >= 350 || rdata['Value'] <= 60)) {
              return ' class="class1" ';
            } else if (rdata["Num"] === '3' && (rdata['Value'] >= 120 || rdata['Value'] <= 20)) {
              return ' class="class1" ';
            } else if (rdata["Num"] === '4' && (rdata['Value'] >= 200 || rdata['Value'] <= 20 || isNaN(rdata['Value']))) {
              return ' class="class1" ';
            } else if (rdata["Num"] === '5' && (rdata['Value'] >= 200 || rdata['Value'] <= 0)) {
              return ' class="class1" ';
            }
          }
        },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM