jqgrid typeahead键值
问题描述:
我使用的twitter引导typeahead和Guriddo jqgrid Version 5.2.1表单编辑。我宁愿用关键值对来做这件事,而不是仅仅重视。下面的所有代码都能正常工作,唯一缺少的是编辑表单打开时显示键(数字)而不是值(公司名称)的现有记录。网格列都是即时创建的。我认为如果在editoptions中,如果我可以指定一个值:公司名称,它可能是一个很好的黑客入侵,但这是行不通的。jqgrid typeahead键值
label: svf.fieldLabel,
name: svf.tf[0].nativename,
width: 150,
editable: true,
edittype: "text",
formatter: 'select',
formatoptions:
{
value: getEditOptionsValue(svf.relatedItemId)
},
editoptions: {
dataInit: function (element) {
var data = JSON.parse(getSelects(svf.relatedItemId));
$(element).attr("autocomplete", "off").typeahead({
appendTo: "body",
dataType: "json",
displayText: function (item) { return item.name; },
source: function (query, process) {
return process(data);
}
});
} //end datainit
}//end edit options
答
为了解决您的问题,您将需要使用自定义的无格式功能。 预定义的无格式函数返回键而不是值。 更多您可以看到我们的documentation here
您可以使用下面的代码:
label: svf.fieldLabel, name: svf.tf[0].nativename, width: 150, editable: true, edittype: "text", formatter: 'select', unformat : function(value, options, cellObject) { return value; },
非常感谢,这做到了。不过,我也使用了自定义格式化程序。 – user1755074
要回答我的问题,使用自定义格式化程序是关键。这样格式化程序不仅适用于网格,而且还适用于编辑表单中的“文本”类型。不过,unformatter也会被使用。 – user1755074