如何使用Fontawesome复选框格式化程序从免费jqgrid中的已发布行中删除操作按钮 [英] How to remove action buttons from posted rows in free jqgrid using Fontawesome checkbox formatter

查看:140
本文介绍了如何使用Fontawesome复选框格式化程序从免费jqgrid中的已发布行中删除操作按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Free jqgrid contain boolean hidden column IsPosted defined as

    {"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是用方法完成的

delete, edit and custom post button needs to be removed from inline actions toolbar if this column has value true. Rhis is done using method

   disableRows('IsPosted', true);

它与Clickable复选框格式器一起使用.如果使用checkboxFontAwesome4格式程序,

It works with Clickable checkbox formatter. If checkboxFontAwesome4 formatter is used,

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

始终为假.我也尝试过

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

但这对于所有格式化程序都是错误的.我也尝试了template = "booleanCheckboxFa",而不是格式化程序行,但这不显示fontawecome图标.

but this is false for all formatters. I tried also template = "booleanCheckboxFa", instead of formatter line but this does not show fontawecome icon.

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

How to fix it so that it works with checkboxFontAwesome4 formatter or with all formatters ?

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

推荐答案

我不确定我是否正确理解了您的问题.可能您只想测试单元格row.cells[iCol]包含选中的符号(类别为fa-check-square-o<i>)还是未标记(类别为fa-square-o<i>).您可以只使用unformatter.如果您喜欢像这样的低级方式

I'm not sure that I correctly understand your question. Probably you want just test whether the cell row.cells[iCol] contained checked symbol (<i> with the class fa-check-square-o) or unckecked (<i> with the fa-square-o). You can just use unformatter. If you prefer low-level way like

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",并且要具有布尔变量,您需要将其转换为true或false.确切地说,返回值取决于使用的editoptions.value. template: "booleanCheckboxFa"使用editoptions: {value: "true:false", defaultValue: "false"}.因此,返回的值是字符串"true""false".如果要将结果完全转换为布尔值,建议您查看这样的简单格式化程序不会使用该值.

where I suppose that this is equal to $grid[0] and cm is colModel[iCol]. The returned value will be the string "true" or "false" and to have boolean variable you need convert it to true or false. To be exactly the returned value depend on editoptions.value which one use. template: "booleanCheckboxFa" uses editoptions: {value: "true:false", defaultValue: "false"}. So the returned value are the string "true" or "false". If you want to make clean conversion of results to Boolean I would recommend you to look at the code of convertOnSave. I included the call of cm.convertOnSave in case if it exist. In common case one should initialize item property of the row, but simple formatters like formatter: "checkboxFontAwesome4" don't uses the value.

这篇关于如何使用Fontawesome复选框格式化程序从免费jqgrid中的已发布行中删除操作按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆