How to get a custom grid param in jqGrid jQuery?

51 views Asked by At

net web forms project and I get data with this format from my ashx.cs http handler file (server side) :

{"total":1,"page":1,"records":10,"userData":{"KoleMoamelat":"1180"},"rows":[{"id":1,"cell":["1"]}]}

and this is a part of the my jqGrid jquery code:

  <script type="text/javascript">
      var grid;
      grid = jQuery("#list").jqGrid({
          url: '/Report/Handlers/AdvancedSearch.ashx',
          datatype: 'json',
          mtype: 'GET',
          colNames: [ 'نوع ملک'],
          colModel: [
              { name: 'Counter', index: 'Counter', width: 40, align: 'center' },
 pager: jQuery('#pager'),
 rowList: [5, 10, 20, 50],
 rowNum: 10,
 height: 120,
 sortname: 'Id',
 sortorder: "desc",
 viewrecords: true,
 imgpath: '/scripts/themes/coffee/images',
 caption: 'آمار قراردادهای ثبت شده در یک بازه زمانی',
 loadComplete: function (data) {
     var userData = $("#list").jqGrid("getGridParam", "userData");
     document.getElementById("lblKoleMoamelat").innerHTML = userData["KoleMoamelat"];

actually the data for the jqGrid table itself is correct without any problem, but I want to access the userData that returned with the jQgrid columns for this segment of code :

document.getElementById("lblKoleMoamelat").innerHTML = userData["KoleMoamelat"];

but this code doesn't get userData from ashx.cs response (server response) :

var userData = $("#list").jqGrid("getGridParam", "userData");

now in html form the element of Id : lblKoleMoamelat unfortunately shows undefined. I appreciate any help.

1

There are 1 answers

1
kaylei sidharth On BEST ANSWER

Here is the code snippet that should help you access the userData from the response and update the HTML element with the correct value:

<script type="text/javascript">
    var grid;
    grid = jQuery("#list").jqGrid({
        url: '/Report/Handlers/AdvancedSearch.ashx',
        datatype: 'json',
        mtype: 'GET',
        colNames: ['نوع ملک'],
        colModel: [
            { name: 'Counter', index: 'Counter', width: 40, align: 'center' },
        ],
        pager: jQuery('#pager'),
        rowList: [5, 10, 20, 50],
        rowNum: 10,
        height: 120,
        sortname: 'Id',
        sortorder: "desc",
        viewrecords: true,
        imgpath: '/scripts/themes/coffee/images',
        caption: 'آمار قراردادهای ثبت شده در یک بازه زمانی',
        loadComplete: function (data) {
            var userData = data.userData; // Access userData directly from the response data
            document.getElementById("lblKoleMoamelat").innerHTML = userData["KoleMoamelat"];
        }
    });
</script>

You should access the userData directly from the data parameter of the loadComplete function. The userData is already part of the response data, so you don't need to use the getGridParam method to access it.