【问题标题】:Jqgrid filter is not working with Dropdownlist in Asp.netJqgrid 过滤器不适用于 Asp.net 中的 Dropdownlist
【发布时间】:2013-01-29 06:28:37
【问题描述】:

嗨,伙计们! 我在 jqgrid 中使用下拉列表实现了过滤器,但网格没有显示我添加过滤器的列的值,也没有过滤数据..

这是我的代码...

<script type="text/javascript">

    var categoriesStr = ":All;1:vikas;2:Ankur";
    $(function () {
        $("#UsersGrid").jqGrid({
            url: 'getGriddahico.ashx',
            datatype: 'json',
            height: 250,
            colNames: ['UserID', 'UserName', 'FirstName', 'MiddleName', 'LastName', 'EmailID'],
            colModel: [
                    { name: 'UserID', index: 'UserID', width: 100, sortable: true, align: 'center' },
                    { name: 'UserName', width: 100, sortable: true, align: 'center' , formatter: 'select', stype: 'select',
                    sorttype: function (cell) { return categories[cell]; },
                    edittype: 'select', editoptions: { value: categoriesStr },
                    searchoptions: { sopt: ['eq'] }
                },
                    { name: 'FirstName', width: 100, sortable: true, align: 'center' },
                    { name: 'MiddleName', width: 100, sortable: true },
                    { name: 'LastName', width: 100, sortable: true, align: 'center' },
                    { name: 'EmailID', width: 150, sortable: true, align: 'center' }
                ],
            rowNum: 10,
            rowList: [10, 20, 30],
            pager: '#UsersGridPager',
            sortname: 'UserID',
            loadonce: true,
            viewrecords: true,
            ignorecase:true,
            sortorder: 'asc',
            autowidth: true,
            toppager: true,
            height: '100%'

        });

        $("#UsersGrid").jqGrid('navGrid', '#UsersGridPager', { edit: false, add: false, del: false, search: false });

        $("#UsersGrid").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true, defaultSearch: "cn", beforeSearch: function () {
            //alert("verifying the data");
            var postData = grid.jqGrid('getGridParam', 'postData');
            // we use `stringResult: true` so decoding of the search parameters are a little complex
            var searchData = jQuery.parseJSON(postData.filters);
            for (var iRule = 0; iRule < searchData.rules.length; iRule++) {
                if (searchData.rules[iRule].field === "UserName") {
                    var valueToSearch = searchData.rules[iRule].data;
                    if (valueToSearch.length != 5) {
                        alert("The search string MUST de 5 charachters length!");
                        return true;    // error
                    }
                }
            }
            return false;
        }
        });

        //jQuery("#UsersGrid").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false });
    });

</script>

欢迎任何帮助...

提前感谢

【问题讨论】:

  • 你能在jsfiddle.net上制作一个现场版吗?
  • categories 在您的代码中似乎是未定义的变量。例如,它应该定义为 var categories = {"1":"vikas", "2":"Ankur"};var categories = ["", "vikas", "Ankur"];

标签: asp.net jqgrid


【解决方案1】:

可能是getGriddahico.ashx 没有返回排序值。 如果能分享getGriddahico.ashx的代码就更好了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-29
    • 2012-09-14
    • 2010-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多