0

I am facing problem when i refresh a jqgrid. Tried many things but still no solution. I want to refresh the grid after getting json data from server side. Here is what i am doing for refreshing jqgrid.

$("#searchButton").on("click",function(){
var url = contextPath+"/patient/fetchPatients?firstName="+$("#firstName").val()+"&lastName="+$("#lastName").val()+"&diagnosis="+$("#diagnosis :selected").val();    
jQuery("#searchedPatientGrid").setGridParam({datatype:'json',url:url}).trigger('reloadGrid');
});

Here is my code for jqgrid config.

jQuery("#searchedPatientGrid").jqGrid({
datatype: "json",
colNames:['id','Firsr Name','Last Name','MObile Number','Action'],
colModel:[
    {name:'id',index:'id', width:100},
    {name:'firstName',index:'firstName', width:100},
    {name:'lastName',index:'lastName', width:100},
    {name:'mobileNumber',index:'mobileNumber', width:100},
    {name:'operationDetails.operationDone',index:'operationDetails.operationDone', width:100}

],
rowNum:10,
rowList:[10,20,30],
pager: '#gridPager',
sortname: 'id',
"width":"900",
"gridview":true,
viewrecords: true,
sortorder: "desc",
loadonce: false,
caption:"Patient Search Result"
});

When i hit the button for first time it hits the server and loads data in grid, but when i hit the search button again it does not hit the server for the data. I dont know why is this happening.Even i have mentioned in config, loadOnce : false. then it should hit the server if i hit the search button.

Kedar Parikh
  • 667
  • 1
  • 11
  • 19

1 Answers1

0

I could guess, that by default if you don't specify mtype parameter of jqgrid it use POST when send request to server, so your URL params can be not sended.

I thinks you can try to use something like this:

    $("#searchButton").on("click", function () {
        var url = contextPath + "/patient/fetchPatients";
        var postData =
            {
                firstName: $("#firstName").val(),
                lastName: $("#lastName").val(),
                diagnosis: $("#diagnosis :selected").val()
            }
    });

    $("#searchedPatientGrid").trigger('reloadGrid',
        [
            {
                datatype: 'json',
                url: url,
                postData: postData
            }]);

For more information how to reload jqgrid with additional params you can check @Oleg answer.

Community
  • 1
  • 1
teo van kot
  • 12,031
  • 10
  • 37
  • 66