简体   繁体   中英

Jqgrid filter is not working with Dropdownlist in Asp.net

hii Guys !! I implemented filter with dropdownlist in jqgrid but grid is not showing the values of the column on which i added filter neither is filtering the data..

Here is my code...

<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>

Anyhelp will be welcomed ...

Thanx in advance

May be getGriddahico.ashx is not returning sorted values. if u could share the code of getGriddahico.ashx , it would be better.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM