javascript - Jqgrid:根据 JSON 值禁用某些复选框

标签 javascript jquery jqgrid free-jqgrid

如果总值(value)小于 500K 或 LTV 比率小于 45%,我想禁用该行和复选框。另外,防止选择禁用的行以支持选择多选列标题中的所有复选框

FIDDLE

  $("#output").jqGrid({
    url: "/echo/json/",
    mtype: "POST",
    datatype: "json",
    postData: {
      json: JSON.stringify(jsonData)
    },
    colModel: [
      /**    { name: 'ClientID', label:'ClientID',width: 80, key: true },****/
      {
        name: 'Symbol',
        width: 65,
        formatter: "showlink",
        formatoptions: {
          baseLinkUrl: "http://www.cnn.com",
          idName: "",
          addParam: function(options) {
            return {
              bankid: options.rowData.Symbol,
              timePeriod: options.rowData.ShareQuantity
            };
          }
        }
      }, {
        name: 'Description',
        width: 165
      }, {
        name: 'ShareQuantity',
        align: 'right',
        width: 85,
        classes: "hidden-xs",
        labelClasses: "hidden-xs",
        formatter: 'currency',
        formatoptions: {
          prefix: " ",
          suffix: " "
        }
      }, {
        name: 'SharePrice',
        label: 'Share Price',
        align: 'right',
        width: 100,
        classes: "hidden-xs",
        labelClasses: "hidden-xs",
        template: "number",
        formatoptions: {
          prefix: " $",
          decimalPlaces: 4
        }
      },
      /*{ label: 'Value1', 
                  name: 'Value1', 
                  width: 80, 
                  sorttype: 'number', 
                  formatter: 'number',
                  align: 'right'
              }, */
      {
        name: 'TotalValue',
        label: 'Total Value',
        width: 160,
        sorttype: 'number',
        align: "right",
        formatter: 'currency',
        formatoptions: {
          prefix: " $",
          suffix: " "
        }
      }, {
        name: 'LTVRatio',
        label: 'LTV Ratio',
        width: 70,
        sorttype: 'number',
        align: "right",
        formatter: 'percentage',
        formatoptions: {
          prefix: " ",
          suffix: " "
        }
      }, {
        name: 'LTVCategory',
        label: 'LTV Category',
        classes: "hidden-xs",
        labelClasses: "hidden-xs",
        width: 120,
        width: 165
      },

      {
        name: 'MaxLoanAmt',
        label: 'MaxLoanAmount',
        width: 165,
        sorttype: 'number',
        align: "right",
        formatter: 'currency',
        formatoptions: {
          prefix: " $",
          suffix: " "
        }
      }

    ],
    additionalProperties: ["Num1"],
    /*beforeProcessing: function (data) {
        var item, i, n = data.length;
        for (i = 0; i < n; i++) {
            item = data[i];
            item.Quantity = parseFloat($.trim(item.Quantity).replace(",", ""));
            item.LTVRatio = parseFloat($.trim(item.LTVRatio *10000).replace(",", ""));
            item.Value = parseFloat($.trim(item.Value).replace(",", ""));
            item.Num1 = parseInt($.trim(item.Num1).replace(",", ""), 10);
            item.Num2 = parseInt($.trim(item.Num2).replace(",", ""), 10);
        }
    }, */
    iconSet: "fontAwesome",
    multiselect: true,
    loadonce: true,
    rownumbers: true,
    cmTemplate: {
      autoResizable: true,
      editable: true
    },
    autoresizeOnLoad: true,
    autoResizing: {
      resetWidthOrg: true,
      compact: true
    },
    autowidth: true,
    height: 'auto',
    forceClientSorting: true,
    sortname: "Symbol",
    footerrow: true,
    caption: "<b>Collateral Value</b> <span class='pull-right' style='margin-right:20px;'>Valuation as of: " + mmddyyyy + "</span>",


    loadComplete: function() {
      var $self = $(this),
        sum = $self.jqGrid("getCol", "Price", false, "sum"),
        sum1 = $self.jqGrid("getCol", "MaxLoanAmt", false, "sum");
      //ltvratio =  $self.jqGrid("getCol","LTVRatio:addas", "Aved Loan Amount");
      $self.jqGrid("footerData", "set", {
        LTVCategory: "Max Approved Loan Amount:",
        Price: sum,
        MaxLoanAmt: sum1
      });
    }
  });

最佳答案

您可以使用rowatr禁用行:

rowattr: function (item) {
    var ratio = parseInt(item.LTVRatio, 10);
    if (item.TotalValue < 500000 || ratio < 45) {
        return {"class": "ui-state-disabled ui-jqgrid-disablePointerEvents"};
    }
}

查看修改后的演示 https://jsfiddle.net/OlegKi/615qovew/117/

关于javascript - Jqgrid:根据 JSON 值禁用某些复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42514468/

相关文章:

javascript附加到文本文件忽略元素

javascript - 如何使用 JQuery 在 Android 浏览器中禁用 'Paste'?

jquery - UIWebview 在 jquery 部分不滚动

javascript - jqGrid - 从 JSON 加载值

jqGrid 需要一个可在添加对话框而不是编辑对话框上编辑的字段

javascript - 不打印 0,1,2,3,4,5...10 打印 10 十次

javascript - 在我的代码末尾使用 .catch 更好吗?

javascript - 增强的 Javascript for 语句可以安全使用吗?

javascript - 日历 : disable selecting certain days

jquery - 使用 jqgrid 的列选择器和 Eric Hynd 的多重选择