free jqGrid search parameter disappearing in filte

2019-07-14 20:21发布

I am using version 4.13.1 of freejqGrid. I just added the code for the filter toolbar, which is working, except that the search parameter disappears after the search. The search works and everything but I would like to leave that text in the toolbar until cleared using the (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");

1条回答
ゆ 、 Hurt°
2楼-- · 2019-07-14 20:40

Free jqGrid 4.13.1 introduced new feature - filling of the filter toolbar based on the postData.filters. See the README4.13.1. The feature had some bugs, which exists in your case. The bugs are fixed in the later version of free jqGrid.

One can switch off the feature by usage loadFilterDefaults: false (by usage .jqGrid("filterToolbar", {loadFilterDefaults: false}) or better by changing searching: { defaultSearch: "cn" } to searching: { defaultSearch: "cn", loadFilterDefaults: false }). On the other side I would better recommend you to update to the current released version of free jqGrid: 4.13.5 or to use the latest sources from GitHub.

The searching option loadFilterDefaults: false is very practical in many scenarios. For example one can use both filter toolbar and the Searching Dialog. If you would set some filter in the filter toolbar and then opening Searching Dialog, then you will see the current filter in the dialog. You can modify it and apply the new filter. The grid will show the new filter, but the old versions of jqGrid will still display old filter in the filter toolbar. I posted the old answer, which shows how one can fill the filter toolbar based on the current used filter. The new version of free jqGrid will refresh the filter toolbar automatically if the default loadFilterDefaults: true option of the filterToolbar is used.

There are other common scenarios where loadFilterDefaults: true would be helpful. One can, for example, load all JSON data from the server using loadonce: true option. Free jqGrid allows to combine loadonce: true option with forceClientSorting: true, which apply local sorting and filtering before the data will be displayed in the grid. It allows to load all the data, but display only filtered and sorted data with paging the data locally. To filter the data one need just set filters property of postData. By usage filterToolbar with default loadFilterDefaults: true option one will see the currently applied filter, which could be helpful for the user.

查看更多
登录 后发表回答