如何在创建jqgrid后应用列模板 [英] How to apply column template after jqgrid is created
问题描述
免费的jqgrid在创建后不会应用列模板。
我试过了
Free jqgrid does not allw to apply column template after it is created. I tried
var newOrderPriceTemplate = {
align: "center",
formatter: "showlink",
formatoptions: {
onClick: function() { alert('clicked'); }
}
};
$(function () {
... code to create jqgrid into $grid
$grid.jqGrid('setColProp', 'Hind', {
template: newOrderPriceTemplate,
search: false
});
});
如果在列中单击,则不会显示警告框。
search:false正确删除搜索字段,因此执行setColProp。
alert box does not appear if clicked in column. search: false removes search field properly so setColProp is executed.
如何在创建jqgrid之后但在显示之前应用newOrderPriceTemplate。
如果在创建时在colModel中指定了模板,它就可以工作。
How to apply newOrderPriceTemplate after jqgrid is created but before displayed. If template is specified in colModel at creation time, it works.
最新的免费jqgrid,jquery,bootstrap 3,aps.net mvc4,.net 4.6是使用。
Latest free jqgrid, jquery, bootstrap 3, aps.net mvc4 , .net 4.6 are used.
推荐答案
我认为对模板的工作方式存在误解。模板不再是将在 $ .extend
中使用的设置列表,以组合来自 colModel
的一些当前属性与模板属性的另一个对象。
I think that there are misunderstanding how templates works. Template is nothing more as the list of settings which will be used in $.extend
to combine some current properties from colModel
with another object of template properties.
我建议阅读免费jqGrid代码的代码片段。在简化形式中,代码看起来像
I recommend to read the code fragment of the code of free jqGrid. In simplified form the code looks like
for (iCol = 0; iCol < p.colModel.length; iCol++) {
p.colModel[iCol] = $.extend(true, {},
p.cmTemplate,
p.colModel[iCol].template || {},
p.colModel[iCol]);
}
换句话说,jqGrid结合了 cmTemplate <的值/ code>,
模板
属性为 colModel
的列的属性。 jqGrid在创建网格时开始。
In other words jqGrid combines the values from cmTemplate
, template
property of the column with the property of colModel
. jqGrid does it at the beginning of creating the grid.
因此,如果你有一些模板( newOrderPriceTemplate
例如),你需要在创建网格后应用 ,然后你需要手动使用 $ .extended
来扩展(并覆盖)现有属性:
Thus if you have some template (newOrderPriceTemplate
for example), which you need to apply after the grid is created, then you need just use $.extend
manually to extend (and overwrite) the existing properties:
var p = $grid.jqGrid("getGridParam");
p.colModel[p.iColByName.Hind] = $.extend(true, {},
p.colModel[p.iColByName.Hind], // old values
newOrderPriceTemplate, // the applied template
{ search: false } // one more setting to apply
);
在当前设置之后放置新属性非常重要 p.colModel [p.iColByName.Hind]
能够覆盖那里。
这篇关于如何在创建jqgrid后应用列模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!