【问题标题】:Jqgrid: disable some checkbox based on JSON valuesJqgrid:禁用一些基于 JSON 值的复选框
【发布时间】:2017-02-28 16:53:53
【问题描述】:

如果 Total Value 为 Les 然后 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
      });
    }
  });

【问题讨论】:

    标签: javascript jquery jqgrid free-jqgrid


    【解决方案1】:

    您可以使用rowattr 禁用行:

    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/

    【讨论】:

    • 快速问题是否可以将引导工具提示合并到链接中?他们有什么例子吗?谢谢
    • @user244394:不客气!一个快速的问题可能需要很长的答案,尤其是演示的答案。 :-) 此外,stackoverflow 分享问题和答案的目标。评论中发布的答案不会被索引,也不会被其他人找到。通常应该发布新的单独问题。
    猜你喜欢
    • 1970-01-01
    • 2013-11-17
    • 1970-01-01
    • 2016-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-25
    • 1970-01-01
    相关资源
    最近更新 更多