[英]jqGrid show an 'edit' icon for in line editing
I am using the jqGrid with inline editing option. 我正在使用带有内联编辑选项的jqGrid。 I want to show an edit icon if the cell does not have any values. 如果单元格没有任何值,我想显示一个编辑图标。
So I write a formatter: 所以我写了一个格式化程序:
function aFormatter(cellvalue, options, row) {
if(cellvalue == null){
return 'you can edit this';
}else{
return cellvalue;
}
}
The you can edit this
text is displayed, when I click on it an input box is displayed correctly, however the input box as the initial value you can edit this
? 将显示you can edit this
文本,当我单击它时正确显示了一个输入框,但是作为初始值的输入框you can edit this
?
How can I fix it? 我该如何解决?
I am using the jqGrid through struts 2 jquery tags plugin
, which is build on jqGrid version 我正在通过struts 2 jquery tags plugin
使用jqGrid,它是基于jqGrid版本构建的
I think that you should define unformatter ( unformat ) together with the formatter. 我认为您应该与格式化程序一起定义unformatter( unformat )。 For example, 例如,
formatter: function (cellvalue) {
if (cellvalue == null) {
return "<span class='ui-icon ui-icon-pencil'></span>";
} else {
return cellvalue;
};
},
unformat: function (cellValue, options, elem) {
return $(elem).text();
}
I'm not sure how you can specify unformat
in the struts2 grid plugin. 我不确定如何在struts2网格插件中指定unformat
。
One more way would be defining formatter in the following way 另一种方法是通过以下方式定义格式化程序
(function ($) {
"use strict";
/*jslint unparam: true */
$.extend($.fn.fmatter, {
yourFormatterName: function (cellValue, options) {
if (cellvalue == null) {
return "<span class='ui-icon ui-icon-pencil'></span>";
} else {
return cellvalue;
};
}
});
$.extend($.fn.fmatter.yourFormatterName, {
unformat: function (cellValue, options, elem) {
return $(elem).text();
}
});
}(jQuery));
It will allows you to use formatter: "yourFormatterName"
(or probably formatter = "yourFormatterName"
in struts2) in the same way like you can use standard formatters "integer"
, "date"
and other. 它将允许您以与可以使用标准格式器 "integer"
, "date"
等相同的方式来使用formatter: "yourFormatterName"
(或在struts2中可能是formatter = "yourFormatterName"
)。
This will show an "edit" icon instead of "you can edit this" in the grid 这将在网格中显示一个“编辑”图标,而不是“您可以编辑此”图标
function aFormatter(cellvalue, options, row) {
if(cellvalue == null) {
return '<span class="ui-icon ui-icon-pencil"></span>'
} else {
return cellvalue;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.