searchString, searchField and searchOper returned as empty from jqGrid in ASP.NET application

萝らか妹 提交于 2019-12-11 09:39:07

问题


I am creating a asp.net mvc application and loaded the data into jqgrid and have paging and sorting working completely. I am trying to implement searching and have implemented code to display the search window; but when I click the Find button, I am unable to retrieve the searchString, searchField and searchOper since they are returned as empty. I am sure that I need to implement postdata code in the javascript but having trouble implementing one. Can anyone point me in the right direction?

Also, any idea about how to implement searching in the controller action??

This is what I have currently in the javascript:

 <script type="text/javascript">
    $(function () {
          $("#list").jqGrid({
              url: '/Home/GetData/',
                    datatype: 'json',
                    mtype: 'GET',
                    colNames: ['ID', 'NAME'],
                    colModel: [
      { name: 'ID', index: 'ID', width: 250, align: 'center', searchoptions: { sopt: ['eq', 'ne', 'cn']} },
      { name: 'NAME', index: 'NAME', width: 250, align: 'center',  searchoptions: { sopt: ['eq', 'ne', 'cn']} }],
                    pager: jQuery('#pager'),
                    rowNum: 10,
                    rowList: [5, 10, 20, 30, 40, 50],
                    sortname: 'ID',
                    sortorder: "desc",
                    viewrecords: true,
                    height: '100%'
                    });

                $("#list").jqGrid('navGrid', '#pager', { edit: true, add: true, del: true, search: true},
                                                        {},
                                                        {},
                                                        {},
                                                        {closeOnEscape: true, multipleSearch: true, closeAfterSearch: true},
                                                        {});


            }); 
</script>

Any help is greatly appreciated!


回答1:


You use multipleSearch: true searching option. It allows to create more powerful queries, but it uses another format of parameters. Instead of three parameters searchString, searchField and searchOper will be used one filters parameter which represent in form of JSON string the full information about the filter. See the documentation for more information.

In the answer for example you will find the code which demonstrate how one can parse the filters parameter and create the corresponding filtering of the data in case of usage Entity Framework for access to the database.



来源:https://stackoverflow.com/questions/11247191/searchstring-searchfield-and-searchoper-returned-as-empty-from-jqgrid-in-asp-ne

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!