如何使用Fontawesome复选框格式化程序从free jqgrid中的已发布行中删除操作按钮
自由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,则需要从内联操作工具栏中删除删除,编辑和自定义发布按钮。 这是使用方法完成的
disableRows('IsPosted', true);
它适用于Clickable复选框格式化程序。 如果使用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 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
)或unckecked( with
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]
而cm
是colModel[iCol]
。 返回的值将是字符串"true"
或"false"
并且要将布尔变量转换为true或false。 准确地说,返回值取决于editoptions.value
使用哪一个。 template: "booleanCheckboxFa"
使用editoptions: {value: "true:false", defaultValue: "false"}
。 所以返回的值是字符串"true"
或"false"
。 如果你想将结果清理转换为布尔值,我建议你看一下convertOnSave的代码。 如果它存在,我包括了cm.convertOnSave
的调用。 在常见的情况下,应该初始化行的item
属性,但是像formatter: "checkboxFontAwesome4"
这样的简单格式化formatter: "checkboxFontAwesome4"
不使用该值。