2

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");
jeffery_the_wind
  • 17,048
  • 34
  • 98
  • 160
  • 2
    Unless you are manually calling refresh on the grid, it shouldn't clear the search parameters. Can you reproduce the problem in a fiddle using static data? – Alexandru Severin Dec 06 '16 at 15:25
  • Yeah there isn't much other code on the page, doesn't seem to be reloading again. Of course after searching it needs to reload to load the new data. I am wondering if I need to pass the search parameter back from the server to the client with the data? – jeffery_the_wind Dec 06 '16 at 15:35
  • I made the fiddle for you and your code is working fine: http://jsfiddle.net/ejnrtocw/121/ . Note: I used jqGrid 4.6.0 , you may try uploading 4.13.1 in it – Alexandru Severin Dec 06 '16 at 15:51
  • Nice thanks, Yes i put the sources for freejqGrid (as i was building a fiddle too) and it works fine in there. Although the local data is much different. I can see on my problem code that the search is cleared out when the new data is loaded from the server. Using local data it seems there isn't much of a reload, but that could just be because it is so fast. – jeffery_the_wind Dec 06 '16 at 16:00
  • 1
    @jeffery_the_wind: You use **old** version of free jqGrid: 4.13.1. You should update to free jqGrid 4.13.5 or the latest code from GitHub. Alternatively you can use `loadFilterDefaults: false` option of the `filterToolbar`. You can use `searching: { defaultSearch: "cn", loadFilterDefaults: false }` – Oleg Dec 06 '16 at 17:26
  • @Oleg OK I will update, but the `loadFilterDefaults: false` also worked. You are the true jqGrid master. – jeffery_the_wind Dec 06 '16 at 17:29

1 Answers1

4

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Updating to the new version allowed this to work without the `loadFilterDefaults: false` option. – jeffery_the_wind Dec 06 '16 at 17:55
  • @jeffery_the_wind: It's what I meant. The new default option `loadFilterDefaults: true` is good, but the first implementation introduced in 4.13.1 contained some bugs. The bugs are fixed in later versions. Thus I recommend to update to the version 4.13.5. The workaround with `loadFilterDefaults: false` should be used only if you can't now update your site to the latest free jwGrid. – Oleg Dec 06 '16 at 18:00
  • Right, I understand. I was just commenting so readers know that both ways will work. You've really done a great job with your fork of this package. – jeffery_the_wind Dec 06 '16 at 18:02