Filter jqGrid programmatically on client?
Asked Answered
A

2

6

Is there a way to filter the data currently displayed in a jqGrid programmatically (in Javascript, not server-side)? All the search examples seem to depend on using jqGrid's own search UI, which doesn't work for me. For example, I'd like to be able to filter based on user actions elsewhere on a page.

I'm imagining something like

jQuery("#grid_id").filter('CategoryID', selectedCategoryID);

where CategoryID is a column in the grid and selectedCategoryID contains, for example, a value chosen by the user in a select element.

Argal answered 7/1, 2010 at 2:14 Comment(0)
N
6

If you want to pre-filter your data first:

$('#myGrid').setGridParam({ data: filtereddataarray }).trigger("reloadGrid");

where filtereddataarray contains only records you want to display for this view

If you want to construct your filter programmatically(I use this method, mostly):

var filters = { "groupOp": "AND", "rules": [{ "field": "id", "op": "eq", "data": "9" }, { "field": "amount", "op": "ge", "data": "10" }, { "field": "name", "op": "cn", "data": "do i"}] };

//To filter:
jqGridFilter(filters , $('#myGrid'));

//To reset: 
jqGridFilter(null, $('#myGrid'));

    function jqGridFilter(filtersparam, grid) {
        grid.setGridParam({
            postData: {
                filters: filtersparam
            },
            search: true
        });
        grid.trigger("reloadGrid");
    }
Northeastward answered 14/2, 2012 at 18:17 Comment(0)
I
1

You could pass JSON as the data and use the setGridParam method to reload the data!

I have never tried this and not sure how you would get jqgrid to use your client data rather than hit a URL!

Have you had any luck?

Incompressible answered 7/1, 2010 at 16:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.