0

免费 jqgrid 包含布尔隐藏列 IsPosted 定义为

    {"label":null,"name":"IsPosted",
 "edittype":"checkbox","editoptions":{"value":"True:False","readonly":"readonly","disabled":"disabled"},
"align":"center",
"formatter":"checkboxFontAwesome4",
"editable":true,
"width":0,"classes":null,
"hidden":true,"stype":"select",
"searchoptions":{"sopt":["eq","ne"],
"value":":Free;true:Yes;false:No"}
    }],

如果此列的值为 true,则需要从内联操作工具栏中删除删除、编辑和自定义发布按钮。Rhis是使用方法完成的

   disableRows('IsPosted', true);

它适用于可点击复选框格式化程序。如果使用 checkboxFontAwesome4 格式化程序,

            isPosted = $(row.cells[iCol]).find(">span>div>input:checked").length > 0;

总是假的。我也试过

            isPosted = $(row.cells[iCol]).children("input:checked").length > 0;

但这对所有格式化程序都是错误的。我也尝试过template = "booleanCheckboxFa",代替格式化程序行,但这没有显示 fontawecome 图标。

如何修复它以使其与 checkboxFontAwesome4 格式化程序或所有格式化程序一起使用?

var disableRows = function (rowName, isBoolean) {
    var iCol = getColumnIndexByName($grid, rowName),
              cRows = $grid[0].rows.length,
              iRow,
              row,
              className,
              isPosted,
              mycell,
              mycelldata,
              cm = $grid.jqGrid('getGridParam', 'colModel'),
              iActionsCol = getColumnIndexByName($grid, '_actions'), l;
    l = cm.length;
    for (iRow = 0; iRow < cRows; iRow = iRow + 1) {
        row = $grid[0].rows[iRow];
        className = row.className;
        isPosted = false;

        if ($(row).hasClass('jqgrow')) {
            if (!isBoolean) {
                mycell = row.cells[iCol];
                mycelldata = mycell.textContent || mycell.innerText;
                isPosted = mycelldata.replace(/^\s+/g, "").replace(/\s+$/g, "") !== "";
            }
            else {
                isPosted = $(row.cells[iCol]).find(">span>div>input:checked").length > 0;
            }
            if (isPosted) {
                if ($.inArray('jqgrid-postedrow', className.split(' ')) === -1) {
                    row.className = className + ' jqgrid-postedrow not-editable-row';
                    $(row.cells[iActionsCol]).attr('editable', '0');
                    $(row.cells[iActionsCol]).find(">div>div.ui-inline-del").hide();
                    $(row.cells[iActionsCol]).find(">div>div.ui-inline-post").hide();
                    $(row.cells[iActionsCol]).find(">div>div.ui-inline-edit").hide();
                }
            }
        }
    }
};
4

1 回答 1

1

我不确定我是否正确理解了您的问题。可能您只想测试单元格是否row.cells[iCol]包含已选中的符号(<i>带有 class fa-check-square-o)或未选中的符号(<i>带有fa-square-o)。你可以只使用 unformatter。如果您更喜欢低级方式,例如

isPosted = $(row.cells[iCol]).find(">span>div>input:checked").length > 0;

那么你可以使用

isPosted = $(row.cells[iCol]).find("i").hasClass("fa-check-square-o");

反而。

更新:一个可以使用

var isPostedStr = $.unformat.call(this, row.cells[iCol],
        {rowId: row.id, colModel: cm}, iCol);
if (cm.convertOnSave) {
    isPosted = cm.convertOnSave.call(this, {
                   newValue: isPostedStr,
                   cm: cm,
                   oldValue: isPostedStr,
                   id: row.id,
                   //item: $grid.jqGrid("getLocalRow", row.id),
                   iCol: iCol
               });
}

我认为这this等于$grid[0]并且cmcolModel[iCol]。返回的值将是字符串"true""false"具有布尔变量,您需要将其转换为真或假。确切的返回值取决于使用editoptions.value哪一种。template: "booleanCheckboxFa"使用editoptions: {value: "true:false", defaultValue: "false"}. 所以返回值是字符串"true""false"。如果您想将结果干净地转换为布尔值,我建议您查看convertOnSave的代码。cm.convertOnSave如果存在的话,我包括了调用。在常见情况下,应该初始化item行的属性,但是像formatter: "checkboxFontAwesome4"不使用该值这样的简单格式化程序。

于 2015-03-30T11:14:36.180 回答