Binging data to jq grid on button click.

Binging data to jq grid on button click.

Hi Team,

I am using jq grid with asp.net mvc4 and C#.

I have a requirement to bind a jq grid with data on click of a button. Currently I did a sample which binds some static data to jq grid on page load itself. But I want to bind the data on click of a button once page loads.

Please find by the below sample for reference that I did for referecnce.

Quick response will be deeply appreciated.


HTML


    jQuery(document).ready(function () {     


        jQuery("#list").jqGrid(


            {


                // url: 'http://localhost:30683/Home/GridData',


                url: '/Home/GridData',


                datatype: 'json',


                contentType: "application/json; charset-utf-8",


                mtype: 'GET',


                colNames: ['Id', 'Votes', 'Title'],


                colModel: [


                  { name: 'Id', index: 'Id', width: 40, align: 'left' },


                  { name: 'Votes', index: 'Votes', width: 40, align: 'left' },


                  {


                      name: 'Title', index: 'Title', width: 200, align: 'left', formatter: 'showlink',


                      formatoptions: { baseLinkUrl: 'javascript:', showAction: "MyBase.GetAndShowUserData(jQuery('#list'),'", addParam: "');" }


                  }


                ],


                pager: '#pager',


                rowNum: 3,


                rowList: [5, 10, 15],


                sortname: 'Id',


                sortorder: "desc",


                viewrecords: true,


                caption: 'My first grid'


            });


    });

    </script>







Code in MVC controller to return dummy data





[HttpGet]




public JsonResult GridData()




{



var jsonData = new




{



total = 1, // we'll implement later




page = 1,



records = 3, // implement later


rows = new[]{


new {id = 5, cell = new[] {"1", "-7", "Is this a good question?"}},


new {id = 6, cell = new[] {"2", "15", "Is this a blatant ripoff?"}},


new {id = 7, cell = new[] {"3", "23", "Why is the sky blue?"}}




}


};


return Json(jsonData, JsonRequestBehavior.AllowGet);




}