inspiringmyself
inspiringmyself

Reputation: 590

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

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!

Upvotes: 1

Views: 2581

Answers (1)

Oleg
Oleg

Reputation: 221997

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.

Upvotes: 2

Related Questions