在JQGrid筛选器工具栏中无法获取用于筛选的下拉列表

时间:2015-05-20 06:26:25

标签: javascript jquery jqgrid

我正在尝试使用此代码获取过滤器工具栏,以便我可以通过选择下拉框进行过滤。但是代码没有显示下拉,而是只显示一个用于过滤的普通框。有人可以告诉我可能犯的错误是什么

    <script type="text/javascript">




      getUniqueNames = function(columnName) {
            var data = $("#grid0").jqGrid('getGridParam', 'data');


            var uniqueTexts = [], text, textsMap = {}, i;

            for (i = 0; i < data.length; i++) {

                text=data[i][columnName];


                             if (text !== undefined && textsMap[text] === undefined) {
                                 // to test whether the texts is unique we place it in the map.
                                 textsMap[text] = true;
                                 if (typeof text =="string" && text.trim()!=''){
                                 uniqueTexts.push(text);
                                 }
                             }
                         }

                     // Object.keys(textsMap); Does not work with IE8: 
                         return uniqueTexts;

        },
        buildSearchSelect = function(uniqueNames) {
            var values=":All";
            $.each (uniqueNames, function() {
                values += ";" + this + ":" + this;
            });
            return values;
        },
        setSearchSelect = function(columnName) {
            $("#grid0").jqGrid('setColProp', columnName,
                        {
                            stype: 'select',
                            searchoptions: {
                                value:buildSearchSelect(getUniqueNames(columnName)),
                                sopt:['eq']
                            }
                        }
            );
        };  

$("#grid0").jqGrid({
            datatype: 'local',
            data: dynaData,
            colNames:dynaCol,
            colMandReq:[-1,-1,-1,-1,-1,-1,-1,-1],
            colModel: [
                   { name: 'c7',width: 60,editable:false, readonly:true,search:true,sortable:false,hidden:false,editable:false },
                   { name: 'c1',width: 60,editable:false, readonly:true,search:true,sortable:false,hidden:false,editable:false },
                   { name: 'c2', width: 120,editable:false, readonly:true,search:false,sortable:false,hidden:false,editable:false },
                   { name: 'c3', width: 55,editable:false, readonly:true,search:false,sortable:false,hidden:false,editable:false },
                   { name: 'c4', width: 55,editable:false, readonly:true,search:false,sortable:false,hidden:false,editable:false },
                   { name: 'c5', width: 75,editable:false, readonly:true,search:false,sortable:false,hidden:false,editable:false },
                   { name: 'c6', width: 50,editable:false, readonly:true,search:false,sortable:false,hidden:false,editable:false },
                   { name:'checkBox', index:'checkBox', align:"center", width: 60, editable:false, editoptions:{value: setDelImage}, hidden:false, sortable:false, search: false,  formatter: setReadOnlyImage,
                    cellattr: function (rowId, val, rawObject, cm, rdata) {return 'title="Click to Authorize"';}
                   },
                   ],
            gridview: true,
            rownumbers: false,
            autoencode: true,
            shrinkToFit: true,
            autowidth: true,
            sortable: false,
            height: '100%',
            rowNum: 100,
            caption:""
            });

$("#grid0").jqGrid('filterToolbar',
        {stringResult:true, searchOnEnter:true, defaultSearch:"cn"});
setSearchSelect('c1');
setSearchSelect('c7');




selectedDynaListNum=-1;
</script> 

0 个答案:

没有答案