jqgrid ajax reload,jqGrid reload grid

问题

It's an addition for previous my question about adding columns into jqGrid-based table. Here my new js-code:

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,

});

}

Now I call createGrid(); after document is loaded, everything works fine. Now I want to add a new column (with empty data) and reload 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

});

But nothing happens, why?

UPD

$("#add_column").click(function() {

col_names.push('New');

col_model.push({name: 'test', index: 'test', width: 100});

$('#list').trigger("reloadGrid");

});

The same situation

UPD2

I tried these:

ajaxGridOptions: {cache: false},

loadonce:false

Didn't change the situation.

回答1:

You can do about following

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();

});

回答2:

try not to Destroy/Create, but .trigger("reloadGrid");

UPD:: try to pass loadonce:false to grid creation params

UPD2:: Seemed like jQgrid cant operate with column changes "On fly". Try to destroy first grid and create another one instead of it.

来源:https://stackoverflow.com/questions/4232430/jqgrid-reload-grid

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值