Max*_*rai 13 javascript jqgrid
这是我之前关于在基于jqGrid的表中添加列的问题的补充.这里是我的新js代码:
var col_names = ['First', 'Second', 'Third', 'Fourth', 'Fifth'];
var col_model = [
{name:'invid', index:'invid', width:100},
{name:'invdate', index:'invdate', width:90},
{name:'amount', index:'amount', width:80, align:'right'},
{name:'tax', index:'tax', width:80, align:'right'},
{name:'total', index:'total', width:80, align:'right'},
];
function createGrid()
{
var handle = $("#list").jqGrid({
url:'data.xml',
datatype: 'xml',
mtype: 'GET',
colNames: col_names,
colModel : col_model,
});
}
Run Code Online (Sandbox Code Playgroud)
现在我createGrid();在加载文档后调用,一切正常.现在我想添加一个新列(带有空数据)并重新加载jqGrid:
$("#add_column").click(function() {
$('#list').trigger("DestroyGrid"); // Also tried UnloadGrid
col_names.push('New');
col_model.push({name: 'test', index: 'test', width: 100});
createGrid(); // And recreate grid
});
Run Code Online (Sandbox Code Playgroud)
但没有任何反应,为什么?
UPD
$("#add_column").click(function() {
col_names.push('New');
col_model.push({name: 'test', index: 'test', width: 100});
$('#list').trigger("reloadGrid");
});
Run Code Online (Sandbox Code Playgroud)
同样的情况
UPD2 我试过这些:
ajaxGridOptions: {cache: false},
loadonce:false
Run Code Online (Sandbox Code Playgroud)
没有改变这种情况.
Ole*_*leg 15
你可以做以下事情
var counter=1; // to be able to click more then one time
$("#add_column").click(function() {
$("#list").jqGrid('GridUnload');
col_names.push('New'+counter);
col_model.push({name: 'test'+counter, index: 'test'+counter, width: 100});
counter++;
createGrid();
});
Run Code Online (Sandbox Code Playgroud)