This is a followup to my earlier question posted here. I have my grid showing up correctly now, thanks to the answer by Oleg. However, now I need to refresh the data in the jqgrid with a different URL on a bootstrap menu item click. Following is my code:
$("#menuitem").click(function(e){
$("#grid").jqGrid('setGridParam', {url: '/getdata?id=1234&name=val.text'});
$('#grid').trigger("reloadGrid");
});
The menu options are added dynamically after we get data from a ajax request. The grid seems to reloading when the reload is triggered. However, it seems to get data from the old URL('/getdata') and not the new one with a different parameter set. I also tried the solution mentioned here, but it did not work in my case as I have dynamically added menu items.
Any help is greatly appreciated.
EDIT: I looked at the page request on firebug. I do not see a request going when I click on the menu item. I also added
$("#list").jqGrid('GridUnload');
to the click handler function as mentioned in the answer to this question. It cleared out the grid for me, but did not reload. So I added the code for jqgrid there and then it worked and the jqgrid displays with the new data. So my code with the changes looks like this:
$("#menuitem").click(function(e){
$("#list").jqGrid('GridUnload');
$("#grid").jqGrid({
url: '/getdata?id=1234&name=val.text'',
datatype: "json",
colNames: ['data'],
colModel: [
{name: 'data', align: 'center'}
],
jsonReader: {
root: "logs",
cell: "",
id: function () {
return function () {
return $.jgrid.randId();
}
},
page: function() { return 1; },
total: function() { return 1; },
records: function(obj) { return obj.logs.length; }
},
loadonce: true,
viewrecords: true,
autowidth: true,
ignoreCase: true,
height: "auto",
rowNum: 999,
autoencode: true,
beforeProcessing: function (data) {
var items = data.data.data.split("\n"), i, l, item;
data.logs = [];
for (i = 0, l = items.length; i < l; i++) {
item = $.trim(items[i]);
if (item.length > 0) {
data.logs.push([item]);
}
}
}
}).jqGrid('filterToolbar', {stringResult: true, searchOnEnter: false, defaultSearch: "cn"});
});
Is there a better way to do this. It looks too cumbersome and heavy for what its doing. Is there a way to get the reload grid to work? I guess this is what goes on internally, but seems too much code when you using the plugin.
thanks,
Asha