Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 免费jqgrid:保存、加载和应用过滤器数据(包括过滤器工具栏文本和页面设置)的更简单方法?_Javascript_Jquery_Jqgrid_Free Jqgrid - Fatal编程技术网

Javascript 免费jqgrid:保存、加载和应用过滤器数据(包括过滤器工具栏文本和页面设置)的更简单方法?

Javascript 免费jqgrid:保存、加载和应用过滤器数据(包括过滤器工具栏文本和页面设置)的更简单方法?,javascript,jquery,jqgrid,free-jqgrid,Javascript,Jquery,Jqgrid,Free Jqgrid,我有一个非常标准的jqGrid使用免费jqGrid 4.13和loadonce:true 我想做的是我几次遇到的事情: 我想保存网格的状态(没有数据) 这意味着设置(例如当前页面的数量)、筛选应用的用户以及筛选工具栏中的文本。 然后稍后将这些数据加载并应用到网格中 jqGrid是一个非常强大的工具,但是像这样的东西似乎很难完成 经过数小时的工作,我想出了一个复杂的解决方案;这是可行的,但这不是一个好的解决方案imho: 1) 保存jqGrid筛选器数据(本地): ? 感谢您的帮助和/或建议 wi

我有一个非常标准的
jqGrid
使用
免费jqGrid 4.13
loadonce:true

我想做的是我几次遇到的事情:
我想保存网格的状态(没有数据)
这意味着设置(例如当前页面的数量)、筛选应用的用户以及筛选工具栏中的文本。
然后稍后将这些数据加载并应用到网格中

jqGrid是一个非常强大的工具,但是像这样的东西似乎很难完成

经过数小时的工作,我想出了一个复杂的解决方案;这是可行的,但这不是一个好的解决方案imho:

1) 保存jqGrid筛选器数据(本地): ?


感谢您的帮助和/或建议

with提供了一个实现示例。方法
refreshSerchingToolbar
相对较长。另一方面,代码还没有满。如果使用选项
searchOperators:true
,则不会还原操作数的状态。我想重写
filterToolbar
方法的许多部分,以便更轻松地保存/恢复过滤器工具栏的状态,或者根据更改的
postData
进行刷新。这只不过是时间的问题而已。您所描述的功能接近于功能
forceClientSorting:true
,这在jqGrid 4.7的原始代码中很难实现,但在我重写了服务器响应的大部分处理之后就很容易实现了。
filterToolbar
的代码也存在同样的问题。
filterToolbar
的更改仍在我的待办事项列表中,我将很快做出相应的更改。

再次感谢您,oleg!很高兴知道目前没有方便的解决方案,所以我可以暂时停止搜索和尝试。我期待着你们的
filterToolbar
等更新版本。在此期间,我将坚持我的变通办法。@low_rents:不客气!我知道最好是表示完美的解决方案,但必须在之前编写相应的代码。此外,jqGrid拥有的功能越多,实现新功能所需的时间就越长,因为我希望该功能在其他选项的不同组合中工作(冻结列、
searchOperators:true
、不同的
guiStyle
值、不同的
stype
等)。尽管如此,我还是决定写我的答案,告诉你们当前的发展状况,并提供一个旧答案的链接。
// in this example i am using the "window unload" event,
// because i want the filters to be saved once you leave the page:

$(window).on("unload", function(){

    // i have to access the colModel in order to get the names of my columns
    // which i need to get the values of the filter-toolbar textboxes later:
    var col_arr = $("#list").jqGrid("getGridParam", "colModel");

    // my own array to save the toolbar data:
    var toolbar_search_array = [];
    for(var i = 0, max = col_arr.length; i < max; i++)
    {
        // only saving the data when colModel's "search" is set to true
        // and value of the filterToolbar textbox  got a length
        // the ID of the filterToolbar text-input is "gs_" + colModel.name
        if(col_arr[i].search && $("#gs_" + col_arr[i].name).val().length)
        {
             toolbar_search_array.push({ name: col_arr[i].name, value: $("#gs_" + col_arr[i].name).val() });
        }
    }

    // putting everything into one object
    var pref = {
        // 1. toolbar filter data - used to fill out the text-inputs accordingly
        toolbar :   toolbar_search_array,

        // 2. postData - contains data for the actual filtering 
        post :      $("#list").jqGrid("getGridParam", "postData"),

        // 3. settings - this data is also included in postData - but doesn't get applied 
        // when using 'setGridParam'
        sortname:   $('#list').jqGrid('getGridParam', 'sortname'),
        sortorder:  $('#list').jqGrid('getGridParam', 'sortorder'),
        page:       $('#list').jqGrid('getGridParam', 'page'),
        rowNum:     $('#list').jqGrid('getGridParam', 'rowNum')

    };

    //saving in localStorage
    localStorage.setItem("list",  JSON.stringify( pref ));
});
var localsave = JSON.parse(localStorage.getItem("list"));

// these settings are also saved in postData, 
// but they don't get applied to the grid when setting the postData:
$('#list').jqGrid('setGridParam', {
    sortname: localsave.sortname,
    sortorder: localsave.sortorder,
    page: localsave.page,
    rowNum: localsave.rowNum
});

// this applies the filtering itself and reloads the grid. 
// it's important that you don't forget the "search : true" part:
$("#list").jqGrid("setGridParam", { 
    search : true,
    postData : localsave.post
}).trigger("reloadGrid");

// this is loading the text into the filterToolbar 
// from the array of objects i created:
console.log(localsave.toolbar);
for(i = 0, max = localsave.toolbar.length; i < max; i++)
{
    $("#gs_" + localsave.toolbar[i].name).val( localsave.toolbar[i].value );
}
// saving:
var my_save = $("#list").jqGrid("getGridParam", "postData");

// loading:
$("#list").jqGrid("setGridParam", { 
    search : true,
    postData : my_save
}).trigger("reloadGrid");