filterToolbar 中消失的免费 jqGrid 搜索参数

free jqGrid search parameter disappearing in filterToolbar

我正在使用 freejqGrid 的 4.13.1 版。我刚刚添加了过滤器工具栏的代码,它可以正常工作,只是搜索参数在搜索后消失了。搜索有效,但我想将该文本保留在工具栏中,直到使用 (x) 清除。

$('#jqGrid_destroyed').jqGrid({
    url:'/url.php',
    height: 'auto',
    shrinkToFit: true,
    width: Math.floor($(window).width()*1),
    datatype: 'json',
    mtype: 'POST',
    colNames:[
        'Flat ID',
        'Customer',
        'Flat #',
        'MiscCode',
        'Item Number',
        'Item Description',
        'plus',
        'RevDate',
        'Created Date',
        'Plate/Flat in QA',
        'Computer Files to Waiting Destruct',
        'Plates/Flat Destroyed',
        'Date Confimation Sent to Customer'
    ],
    colModel:[
        {name:'flat_id',hidden:true},
        {width:14,name:'Customer'},
        {width:10,name:'flat_plate_num'},
        {width:13,name:'MiscCode'},
        {width:20,name:'item_number'},
        {width:45,name:'item_description'},
        {width:12,name:'plus'},
        {width:16,name:'revdate'},
        {width:22,name:'created_date', align: "right", hidden:true},
        {width:17,name:'flat_in_qa'},
        {width:20,name:'computer_files_to_waiting_destruct'},
        {width:25,name:'flat_destroyed'},
        {width:20,name:'date_confimation_sent_to_customer', formatter : 'date', formatoptions : {srcformat: "Y-m-d", newformat:"m/d/Y"}}
    ],
    sortname: 'date_confimation_sent_to_customer',
    sortorder: 'desc',
    viewrecords: true,
    gridview: true,
    caption: 'Waiting Destruct',
    rowNum: 10000,
    pager:true,
    searching: { defaultSearch: "cn" }
}).jqGrid("filterToolbar");

free jqGrid 4.13.1引入了新特性——基于postData.filters的过滤器工具栏的填充。参见README4.13.1。该功能有一些错误,您的情况存在这些错误。这些错误在以后版本的免费 jqGrid 中得到修复。

可以通过使用 loadFilterDefaults: false 关闭该功能(通过使用 .jqGrid("filterToolbar", {loadFilterDefaults: false}) 或将 searching: { defaultSearch: "cn" } 更改为 searching: { defaultSearch: "cn", loadFilterDefaults: false } 更好)。另一方面,我最好建议您更新到当前发布的免费 jqGrid 版本:4.13.5 或使用来自 GitHub.

的最新资源

搜索选项loadFilterDefaults: false在很多场景下都非常实用。例如,可以同时使用 过滤器工具栏和搜索对话框。如果您要在过滤器工具栏中设置一些过滤器,然后打开“搜索对话框”,那么您将在对话框中看到当前过滤器。您可以对其进行修改并应用新过滤器。网格将显示新过滤器,但旧版本的 jqGrid 仍将在过滤器工具栏中显示 旧过滤器。我发布了 the old answer,它展示了如何根据当前使用的过滤器填充过滤器工具栏。如果使用 filterToolbar 的默认 loadFilterDefaults: true 选项,新版本的免费 jqGrid 将自动刷新过滤器工具栏

还有其他常见情况 loadFilterDefaults: true 会有所帮助。例如,可以使用 loadonce: true 选项从服务器加载所有 JSON 数据。免费的 jqGrid 允许将 loadonce: true 选项与 forceClientSorting: true 组合,这适用于 local sortingfiltering之前的数据会显示在网格中。它允许加载所有数据,但仅显示过滤和排序的数据,并在本地分页数据。要过滤数据,只需设置 filters 属性 of postData。通过使用 filterToolbar 和默认 loadFilterDefaults: true 选项,您将看到当前应用的过滤器,这可能对用户有帮助。