0

JQGrid と Multiselect フィルターを使用して、個々の列をフィルター処理しています。現在、データベースのマスター値を使用してフィルター (SkillCategory 列など) を設定しています。

{
 name: 'SkillCategory', index: 'SkillCategory', width: '5%', sortable: true, resizable: true, stype: 'select',
  searchoptions: {
  clearSearch: false,
   sopt: ['eq', 'ne'],
    dataUrl: 'HttpHandler/DemandPropertyHandler.ashx?demprop=skillcat',
    buildSelect: createSelectList,
     attr: { multiple: 'multiple', size: 4 },
     position: {
      my: 'left top',
         at: 'left bottom'
        },
     dataInit: dataInitMultiselect
      }
    },

このアプローチでは、使用可能なすべてのマスター リスト (SkillCategory 用) をフィルターに入力しています。特定の列 (SkillCategory) で使用可能な行に存在するものに基づいて、使用可能なフィルター値のみを表示したいと思います。これは、SkillCategory フィルターのオプションとして「プログラミング」と「データ」を表示する必要があります。行には、その列の「プログラミング」と「データ」の値のみが含まれているためです。

ここに画像の説明を入力

ここに画像の説明を入力

以下のコードを見つけました(リンクを忘れてすみません)

getUniqueNames = function (columnName) {
            var texts = $("#listTableSupply").jqGrid('getCol', columnName), uniqueTexts = [],
            textsLength = texts.length, text, textsMap = {}, i;
            for (i = 0; i < textsLength; i++) {
                text = texts[i];
                if (text !== undefined && textsMap[text] === undefined) {
                    // to test whether the texts is unique we place it in the map.
                    textsMap[text] = true;
                    uniqueTexts.push(text);
                }
            }
            return uniqueTexts;
        }
        buildSearchSelect = function (uniqueNames) {
            var values = ":All";
            $.each(uniqueNames, function () {
                values += ";" + this + ":" + this;
            });
            return values;
        }
        setSearchSelect = function (columnName) {
            $("#listTableSupply").jqGrid('setColProp', columnName,
                    {
                        searchoptions: {
                            sopt: ['eq', 'ne'],
                            value: buildSearchSelect(getUniqueNames(columnName)),
                            attr: { multiple: 'multiple', size: 3 },
                            dataInit: dataInitMultiselect
                        }
                    }
        );
        }

setSearchSelect("SkillCategory") の呼び出し

....  caption: 'Supply',
                emptyrecords: "No records to view",
                loadtext: "Loading...",
                refreshtext: "Refresh",
                refreshtitle: "Reload Grid",
                loadComplete: loadCompleteHandler1,
                ondblClickRow: function (rowid) {
                    jQuery(this).jqGrid('viewGridRow', rowid);
                },
                beforeRequest: function () //loads the jqgrids state from before save
                {
                    modifySearchingFilter.call(this, ',');
                }
            }).jqGrid('bindKeys');
            $('#listTableSupply').bind('keydown', function (e) {
                if (e.keyCode == 38 || e.keyCode == 40) e.preventDefault();
            });
            setSearchSelect("SkillCategory");
            $('#listTableSupply').jqGrid('navGrid', '#pagerSupply', {
                cloneToTop: true,
                refresh: true, refreshtext: "Refresh", edit: false, add: false, del: false, search: false
            }, {}, {}, {}, {
                multipleSearch: true,
                multipleGroup: true,
                recreateFilter: true
            }); .....

しかし、うまくいかないようです。「すべて」の値のみが入力されます。 ここに画像の説明を入力

どうすればこれを達成できますか。

アップデート1:

以下のオレグの提案によると、私のために働いた作業コードです。

initializeGridFilterValue = function () {

            //jQuery("#listTableSupply").jqGrid('destroyGroupHeader');
            setSearchSelect("SkillCategory");

            jQuery("#listTableSupply").jqGrid("filterToolbar", {
                stringResult: true,
                searchOnEnter: true,
                defaultSearch: myDefaultSearch,
                beforeClear: function () {
                    $(this.grid.hDiv).find(".ui-search-toolbar .ui-search-input>select[multiple] option").each(function () {
                        this.selected = false; // unselect all options
                    });

                    $(this.grid.hDiv).find(".ui-search-toolbar button.ui-multiselect").each(function () {
                        $(this).prev("select[multiple]").multiselect("refresh");
                    }).css({
                        width: "98%",
                        marginTop: "1px",
                        marginBottom: "1px",
                        paddingTop: "3px"
                    });
                }
            });
            jQuery("#listTableSupply").jqGrid('setGridHeight', 300);
        }

以下のように loadComplete イベントから設定します。

function loadCompleteHandler1() {
            initializeGridFilterValue();
        }
4

1 に答える 1

2

私の古い回答のコードを使用しているようです。あなたの問題について:最初filterToolbarにフィルターツールバーを作成するを呼び出し、後でsetSearchSelect新しいsearchoptions.valueプロパティを設定するを呼び出すと思います。もう 1 つの考えられる問題は、データがグリッドにロードされるsetSearchSelect 前に呼び出すことです。datatype: "local"パラメータとともに使用するとdata、グリッドの作成中にデータがグリッドに入力されます。を使用する場合datatype: "json"は、最初にサーバーからデータをロードしてから、内部でsetSearchSelectandを呼び出す必要があります。たとえば、を使用すると、内のパラメータの値をテストできます。値が の場合、データの初期ロードを行いました。だからあなたは電話するべきですfilterToolbarloadCompleteloadonce: truedatatypeloadComplete"json"setSearchSelect、必要に応じて呼び出しdestroyFilterToolbar、最後に呼び出し filterToolbarてフィルターツールバーを作成し、必要なすべての値を選択します。

于 2014-11-17T13:01:28.870 に答える