Make 'Search' remote and everything else (sorting, pagination, etc) local in jqGrid

前端 未结 2 910
暖寄归人
暖寄归人 2020-12-19 19:31

I\'m working on a Django project which uses JQgrid to display data from the db.

What I\'m looking to achieve is to have only the search option wired to perform a rem

2条回答
  •  被撕碎了的回忆
    2020-12-19 19:46

    If you look at the below code I'm doing a search between two dates on the toolbar, "e" is the Id of my control I'm using. Now the key factor is the property called "search", if you set this to "true" it will do a client search, false will do a remote search to whichever ajax method you would call for your search.

            var gridFilter;
            var fieldId = e.replace('#', '');
            var fieldForFilter = fieldId.replace('gs_', '');//All toolbar filters Id's are the same as the column Id but prefixed with "gs_"
            var splitteddates = $("#" +fieldId).val().split('-');
            var grid = $("#GridJq1");
            gridFilter = { groupOp: "AND", rules: [] };
            gridFilter.rules.push({ field: "" + fieldForFilter + "", op: "gt", data: "" + $.trim(splitteddates[0]) + "" });
            gridFilter.rules.push({ field: "" + fieldForFilter + "", op: "lt", data: "" + $.trim(splitteddates[1]) + "" });
            grid[0].p.search = true;//specifies wether to do a client search or a server search which will be done manually. true=client search
            $.extend(grid[0].p.postData, { filters: JSON.stringify(gridFilter) });//combine post data and newly added filter data
            grid.trigger("reloadGrid", [{ page: 1, current: true}]);//reset to page and keep current selection if any
    

    If I recall correctly, part of the above code for building the search is from an answer from the famous JQGrid Oleg so kudos to him if this was part of his code.

提交回复
热议问题