jqGrid: Searching with json data

I have succeeded to load data from server in spring framework with pagination but my searching/finding records and filter bar is not working.

But if i make loadonce=true then the filter or searching working fine.

My code for my jsp is:

var allColumnNames=["Sr. No","contactName", "city", "country"];

 var grid = jQuery('#list');

        grid.jqGrid({
            url:'customerData.html',
            datatype: 'json',
            mtype: 'GET',               
            loadonce: false,

            colNames: allColumnNames,
            colModel: [

                { name:'id', index:'id', jsonmap:"id", width:20,index:'id', search:true, stype:'int' ,hidden:true},
                { name: "contactName" ,index:'contactName', width:160, search:true, stype:'text' },
                { name: "city",index:'city', width:160, search:true, stype:'text'  },
                { name: "country" ,index:'country', width:160, search:true, stype:'text' }
            ],
             caption: 'Customer Details',
                height: 'auto',
                gridview: true,
                rownumbers: true,
                viewrecords: true,
                pager: '#pager',
                rowNum: 10,
                rowList: [5, 10, 20, 50],                  
                rownumbers: true
            });

           $("#search").click(function() {
            var searchFiler = $("#filter").val(), f;

            if (searchFiler.length === 0) {
                grid[0].p.search = false;
                $.extend(grid[0].p.postData,{filters:""});
            }
            f = {groupOp:"OR",rules:[]};
            f.rules.push({field:"contactName",op:"cn",data:searchFiler});
            f.rules.push({field:"city",op:"cn",data:searchFiler});
            grid[0].p.search = true;
            $.extend(grid[0].p.postData,{filters:JSON.stringify(f)});
            grid.trigger("reloadGrid",[{page:1,current:true}]);
        }); 

I am new to jqGrid, Please help me in above problem.

Thanks in advance!

Answers


When you put loadonce=true jqGrid only makes one request that takes all the data, and then if you filter, sort, search... are controlled by jqGrid in the frontend.

But if loadonce=false, only loads the data needed at this moment, and every time jqGrid needs new data, it sends another request to the server with differents parameters.

So I can guess that your server file "customerData.html", it's not ready to answer all the different questions.

Here http://trirand.com there are a lot of jqGrid examples an most of them have the server side code.


Need Your Help

Release Core Foundation object

ios iphone core-foundation

Hey I use this method to return NSData.

How to Create Customized Time Bar in iPhone?

iphone objective-c ios customization quartz-graphics

I need to create a time bar like the image attached.The blue lines are the dates indicating some actions.The big Red Arrow mark is used to slide for selecting any of the blue line. At background ...