Search code examples
jqueryjqgrid

How to make jqgrid only works (show data) when we are searching?


I use jqgrid with toolbar search. I want jqgrid to show empty grid when on load and show empty grid when i reset/clean toolbar search. So i want dedicate this jqgrid just for searching.

How to make jqgrid only works (show data) when we are searching?

Thank you.

Best Regards,

Eka


Solution

  • You can use certain event to do this.

    Initially your grid maybe will need to have datatype : local and empty data parameter i.e

    jqGrid({
        ...
        datatype: 'local',
        data : [],
        ...
    });
    

    When calling the toolbar filter use the two events - beforeClear and beforeSearch - see the docs for this purpose.

    In beforeSearch event set datatype to 'json' and eventually the url, in beforeClear set the datatype again to local