我正在经历的jqGrid 4.3.1的文档和源代码ColNames当谈到为tableToGrid()
功能,我发现,列入options
当ColModel
和ColNames
被忽略对象,因为它们是从HTML表格布局构建的。的jqGrid tableToGrid()被忽略colModel和期权
我的问题是有办法强制tableToGrid()
接受这两个数组(ColModel,ColNames)
,而不是将它们从HTML表格中构建出来,特别是如果事先已知表格列。
当我通过代码去了,我发现在这部分程序为
function tableToGrid(selector, options) {
...
...
// Build up the columnModel and the data
var colModel = [];
var colNames = [];
jQuery('th', jQuery(this)).each(function() {
if (colModel.length === 0 && selectable) {
colModel.push({
name: '__selection__',
index: '__selection__',
width: 0,
hidden: true
});
colNames.push('__selection__');
} else {
colModel.push({
name: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
index: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
width: jQuery(this).width() || 150
});
colNames.push(jQuery(this).html());
}
});
然而,我的破解会考虑这些变化
function tableToGrid(selector, options) {
...
...
// Build up the columnModel and the data
if(options.hasOwnProperty("colModel") && options.hasOwnProperty("colNames")) {
var colModel = options.colModel;
var colNames = options.colNames;
} else {
var colModel = [];
var colNames = [];
jQuery('th', jQuery(this)).each(function() {
if (colModel.length === 0 && selectable) {
colModel.push({
name: '__selection__',
index: '__selection__',
width: 0,
hidden: true
});
colNames.push('__selection__');
} else {
colModel.push({
name: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
index: jQuery(this).attr("id") || jQuery.trim(jQuery.jgrid.stripHtml(jQuery(this).html())).split(' ').join('_'),
width: jQuery(this).width() || 150
});
colNames.push(jQuery(this).html());
}
});
}
我只是想知道,如果有一个更简单的方法(可能是我错过的一个选项),可以强制执行此类行为,而无需调整源代码。
我这样做的原因首先是为某些字段强制datefmt
选项,因为它们被jQgrid忽略,导致搜索功能出现问题。如果@ Oleg可以提供一些关于这方面的见解,它将非常感激。
干杯,N.
[你认为'colModel'和'colNames'是否被忽略了?](http://jsfiddle.net/darkajax/4esFf/) – DarkAjax 2012-04-04 20:07:09
从现有的HTML表格构建jqGrid时没有考虑它们。 – nawar 2012-04-04 20:11:24