0

I'm using jqGrid 4.4.5 and the toolbar filter.The grid can reloads base on condition(for example inbox or outbox letters).I use select options of a column.I need to change the select options of a 'type' column.For example if the grid show 'inbox letter' Then 'select options' show 'A,B' Otherwise show 'C,D'. I use this code for create grid:

function creatGrid() {

var inboxSearchOptions = 'A:A;B:B;All:';//inbox Options
var inboxEditOptions = 'A:A;B:B';

var outboxSearchOptions = 'C:C;D:D;ALL:';
var outboxEditOptions = 'C:C;D:D';

grid.jqGrid({
    url: 'jqGridHandler.ashx',
    datatype: 'json',
    width: 100,
    height: 200,
    colNames: ['Email', 'Subject', 'Type', 'ID'],
    colModel: [
        { name: 'Email', width: 100, sortable: false, },
        { name: 'Subject', width: 100, sortable: false, },
        {
            name: 'Type',
            width: 100,
            search: true,
            formatter: 'select',
            edittype: 'select',
            editoptions: { value: (($.cookie("calledFrom") == "inbox") ? inboxEditOptions : outboxEditOptions), defaultValue: 'ALL' },
            stype: 'select',
            searchoptions: { sopt: ['eq', 'ne'], value: (($.cookie("calledFrom") == "inbox") ? inboxSearchOptions : outboxSearchOptions) },
        },
        { name: 'ID', width: 100, sortable: false, hidden: true, key: true },
    ],
    rowNum: 20,
    loadonce: true,
    rowList: [5, 10, 20],
    recordpos: "left",
    ignoreCase: true,
    toppager: true,
    viewrecords: true,
    multiselect: true,
    sortorder: "desc",
    scrollOffset: 1,
    editurl: 'clientArray',
    multiboxonly: true,
    jsonReader:
    {
        repeatitems: false,
    },
    gridview: true,
}

}

Then i use this code for reload grid:

function doReloadMainGrid() {

switch (($.cookie("calledFrom")) ) {
case "inbox":
    {
        window.grid.setColProp("Type", {
            searchoptions: {
                value: inboxSearchOptions,
            },
            editoptions: {
                value: inboxEditOptions
            },                    
        });
    }
    break;
case "outbox":
    window.grid.setColProp("Type", {
        searchoptions: {
            value: outboxSearchOptions,
        },
        editoptions: {
            value: outboxEditOptions
        },                    
    });
    break;
}

var url = createUrl();
window.grid.setGridParam({ datatype: 'json' });
window.grid.setGridParam({ url: url });
window.grid.trigger("reloadGrid", { current: true });

}

But the 'setColProp' has no effect.I read this answer but it was not a good solution for me.What i got wrong? Thanks in advance

Community
  • 1
  • 1
ZSH
  • 631
  • 5
  • 16
  • 36

1 Answers1

0

setColProp don't change existing filter toolbar. If you just get the values from cookie or localStorage than it would be better to do this before the filter toolbar will be created by filterToolbar method.

You can use destroyFilterToolbar to recreate the filter toolbar using new values in colModel. If you have to use old version of jqGrid you can just follow the answer which describe how to add the code destroyFilterToolbar to old version of jqGrid.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798