NullPointerException
NullPointerException

Reputation: 3814

jQGrid reload not working once table becomes empty

I am having an issue with jqGrid relaod.

So here is what I have.

when my page load I build a table

  $("#systemPropList").jqGrid(
        {
          url : '${servletPath}/systemProperties.data',
          colNames:['Key Name','Key Value','Description','System Name','Work'],
          colModel : [
                {name:'propertyKey',index:'propertyKey', width:155, align:'center'},
                {name:'propertyValue',index:'propertyValue', width:100, align:'center'},
                {name:'propertyDescription',index:'propertyDescription'},
                {name:'propertySystemName',index:'propertySystemName', width:100, align:'center'},
                {name:'propertyId', sortable:false, width:60, align:'center', formatter:workButtons }
          ],
          sortname: 'propertyKey',
          sortorder: "desc"
        })

I have a select box on the top to reload this table based on the value selected from dropbox and I have bind the reload to the onChange.

 $("select[name=systemName]").change(function(obj){
            gridReload();
 });

    function gridReload(){
     $("#systemPropList").setGridParam({"page": 1});
     $("#systemPropList").jqGrid("setGridParam",{postData:{propertySystemName :     $("#systemName option:selected").val()}}).trigger("reloadGrid");
    }

This works fine till I select an option for which the data is available .But once I select an option that does not have any data, the table becomes empty and after the table remains empty even if I change the selection.

I checked through the firebug there is not JS error and the reload is making the correct call to server and server is returning the data.

What am I missing ?

Upvotes: 4

Views: 618

Answers (1)

Oleg
Oleg

Reputation: 222017

First of all I think you should better use postData with propertySystemName defined as function:

postData: {
    propertySystemName: function () {
        return $("#systemName option:selected").val();
    }
}

(see the answer for more details). After that you will don't need to reset propertySystemName inside of change (or inside of gridReload).

What you can try to do is the following

function gridReload() {
    $("#systemPropList").jqGrid("setGridParam", {lastpage: 1})
        .trigger("reloadGrid", [page: 1]);
}

Upvotes: 2

Related Questions