Reputation: 19912
I am using jqGrid but due to my server side technology I cannot call a URL directly to get the data and can only post to the server via a 3rd party broker. My goal is to be able to load data into the Grid via calling my own JavaScript function that calls the server and returns a JSON string.
What I tried: instead of
url:'http://127.0.0.1/products/index.php’,
datatype: 'json',
I have
datastring:init(),
datatype: 'jsonstring',
my init()
function does the server-side call. It works fine for the initial page load. However it is never called again e.g. when I jump between pages, or change the number of rows to view. I need it to recall my init function to refresh the data from the database. However it does not ever call my init()
function more than once. I assume it thinks this is a hard coded string which never changes.
I tried to call $("#mygrid").trigger("reloadGrid");
manually but it doesn’t seem to work either.
My Grid is:
<script type="text/javascript">
$(function(){
$("#list").jqGrid({
datastr:init(),
datatype: 'jsonstring',
mtype: 'GET',
beforeRequest: beforeReq,
pager: '#pager',
rowNum:5,
rowList:[5,10,30],
sortname: 'invid',
sortorder: 'desc',
grouping:true,
viewrecords: true,
gridview: true,
});
});
</script>
I tried calling
$("#list").setGridParam({datatype:'jsonstring', page:1}).trigger('reloadGrid');
I tried what Oleg has suggested here and here but it still does not seem to call my init function again.
Upvotes: 1
Views: 2584
Reputation: 222017
You current code calls init()
once before creating the grid. Then it create the grid using the result returned from init()
.
If you really need to use datatype: 'jsonstring'
(and not datatype: "local"
with additional data
parameter) then you can reset the value of datastr
parameter before calling reloadGrid
. The corresponding code could be about the following:
$("#list").setGridParam({
datatype: "jsonstring",
datastr: init()
}).trigger("reloadGrid", [{page: 1}]);
Upvotes: 1