how to show filtered jqgrid with search toolbar prefilled using single call to retrieve data

末鹿安然 提交于 2020-01-06 14:17:35

问题


I'm looking for a way to show jqgrid with search toolbar pre-filled and data filtered by this toolbar. I tried code below but this makes two requests to retrieve data. First request retrieves unfiltered data and only second request retrieves proper data.

How to eliminate first request so that filtered data is retrieved and search toolbar is pre-filled immediately ?

var grid = $("#grid"),
    notLoaded= true;
grid.jqGrid({
datatype: "json",
mtype: 'POST',
   loadComplete: function() { 
     $("#gs_Name").val('<%= Request.QueryString["Name"] %>');
     if (notLoaded) {
       setTimeout( function() {
         $("#grid")[0].triggerToolbar();
         }, 100 );
       notLoaded = false;
       }
     }
 });

Update

I tried to fill search toolbar using search criteria passed from query string

$(function () {
    var grid = $("#grid"),
        urlFilters;
    var namedParameters = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'),
        parameters = {}, 
        nameAndValue, 
        i; 
    for (i = 0; i < namedParameters.length; i += 1) { 
        nameAndValue = namedParameters[i].split('='); 
        parameters[nameAndValue[0]] = decodeURIComponent(nameAndValue[1]); 
        if (nameAndValue[0] === "filters") { 
            urlFilters= decodeURIComponent(nameAndValue[1]); 
        } 
    } 

    grid.jqGrid({
     postData: { filters: urlFilters }, 
     search:true, 
     loadComplete: function() { 
         refreshSearchingToolbar( $(this), 'eq');
         }
     ...

Search toolbar is empty if grid is loaded but grid is filtered and find dialog is filled properly. Search toolbar is also filled if find dialog is opened.

Debugger shows that in refreshSearchingToolbar condition

if (typeof (postData.filters) === "string" &&
                        typeof ($grid[0].ftoolbar) === "boolean" && $grid[0].ftoolbar) {

if not satisfied: ftoolbar is undefined. I removed this check but after that got error at line tagName = control[0].tagName.toUpperCase(); about undefined tagName How to fix this ?


回答1:


You should create jqGrid with search: true and postData: {filters: theFilterAsJSON} parameters. Look the answer, this one of this one for details.

UPDATED: The answer shows how to parse postData.filters and fill the fields of the searching toolbar (whenever it's possible) the the corresponding filters.



来源:https://stackoverflow.com/questions/8279319/how-to-show-filtered-jqgrid-with-search-toolbar-prefilled-using-single-call-to-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!