【问题标题】:How to remove action buttons from posted rows in free jqgrid using Fontawesome checkbox formatter如何使用 Fontawesome 复选框格式化程序从免费 jqgrid 中的已发布行中删除操作按钮
【发布时间】:2015-06-03 07:00:40
【问题描述】:

免费 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();
                }
            }
        }
    }
};

【问题讨论】:

  • 你能在 codepan 或 jsfiddle 中提供你的代码吗?
  • 您写了formatter: "actions" 的问题,但您没有发布使用格式化程序的列的定义。另一方面,您发布了使用formatter:"checkboxFontAwesome4" 的列的定义,但格式化程序与编辑无关。您的问题是:如何测试IsPosted 列中的值?你到底有什么问题?
  • 如果使用 template = "booleanCheckboxFa",我需要测试 IsPosted 列的值。 queston 代码中提供的测试仅适用于formatter = "clickableCheckbox"

标签: javascript jquery jqgrid free-jqgrid


【解决方案1】:

我不确定我是否正确理解了您的问题。可能您只想测试单元格 row.cells[iCol] 是否包含选中符号(&lt;i&gt;fa-check-square-o 类)或未选中符号(&lt;i&gt;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" 这样的简单格式化程序不使用该值。

【讨论】:

  • 谢谢。有效。此代码从 loadComplete 事件中调用。如何改用 unformatter ? Unformatter 适用于任何格式化程序,因此更通用。
  • @Andrus:不客气!我在答案中添加了 UPDATED 部分。
  • jqgrid 允许根据ok-soft-gmbh.com/jqGrid/OK/CustomActionButton.htmgithub.com/free-jqgrid/jqGrid/commit/… 在属性中添加操作按钮 问题和答案中的代码仍然可以用来删除标准和自定义操作按钮还是有更好的方法?
  • @Andrus:是的。如果可能的话,我尽量保持对旧版本 jqGrid 的兼容性。使用新功能的主要优点是性能和使用简单。您知道格式化程序、自定义格式化程序、rowattrcellattrgridview: true 一起工作得非常快,因为 jqGrid 生成 整个网格作为字符串并将其作为一个操作放置在页面上。答案中的代码修改列的每个单元格。每次修改都遵循浏览器重排以重新计算其他元素的位置。所以老办法是慢慢来的。
  • @Andrus:新方法允许自定义formatter: "actions",以便在创建操作按钮期间直接包含自定义按钮。因此,只需在formatoptions: {...} 或选项actionsNavOptions 中指定一些选项。我现在正在写新的 wiki 文章,详细描述新功能。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-27
  • 1970-01-01
  • 2012-04-10
  • 1970-01-01
  • 2014-04-18
  • 1970-01-01
  • 2015-06-26
相关资源
最近更新 更多