views:

23

answers:

1

I have all the required javascript included, and the proper locale (at least, I think):

 <script type="text/javascript" src="http://localhost/Web/Scripts/jqgrid/js/jquery.jqGrid.min.js"&gt;&lt;/script&gt;
 <script type="text/javascript" src="http://localhost/Web/Scripts/jqgrid/js/i18n/grid.locale-en.js"&gt;&lt;/script&gt;

Here's the javascript:

<script type="text/javascript">
    jQuery(document).ready(function() {
        //var url = 'http://' + window.location.hostname + '/Web/Service/Kpi/MonthlyGrid?orgName=' + orgName + '&month=3';
        var url = 'http://' + window.location.hostname + '/Web/Service/Kpi/MonthlyGrid';
        console.log(url);
        $.getJSON(url,
                    function(data) { console.log(data); });
        jQuery("#list").jqGrid({
            url: url,
            datatype: 'json',
            mtype: 'GET',
            colNames: ['ID','SITE_TYPE_ID', 'ORG_UNIT_ID', 'SITE_ID', 'AREA_ID', 'MONTH', 'YEAR', 'VALUE', 'IS_UNRELIABLE', 'CALCULATED_ON'],
            colModel: [
            { name: 'ID', index: 'ID', width: 40, align: 'left' },
          { name: 'SITE_TYPE_ID', index: 'SITE_TYPE_ID', width: 40, align: 'left' },
          { name: 'ORG_UNIT_ID', index: 'ORG_UNIT_ID', width: 40, align: 'left' },
          { name: 'SITE_ID', index: 'SITE_ID', width: 40, align: 'left' },
          { name: 'AREA_ID', index: 'AREA_ID', width: 40, align: 'left' },
          { name: 'MONTH', index: 'MONTH', width: 40, align: 'left' },
          { name: 'YEAR', index: 'YEAR', width: 40, align: 'left' },
          { name: 'VALUE', index: 'VALUE', width: 40, align: 'left' },
          { name: 'IS_UNRELIABLE', index: 'IS_UNRELIABLE', width: 40, align: 'left' },
          { name: 'CALCULATED_ON', index: 'CALCULATED_ON', width: 40, align: 'left'}],
            pager: jQuery('#pager'),
            rowNum: 10,
            rowList: [5, 10, 20, 50],
            sortname: 'ID',
            sortorder: "desc",
            viewrecords: true,
            imgpath: '/scripts/themes/coffee/images',
            caption: 'My first grid'
        });
    }); 
</script>

And lastly, the data returned from the URL:

{"page":1,"total":1,"records":6,"rows":
[{"id":"8F4CEED3-628E-9EE7-E040-000A3E0034B3","cell":["8F4CEED3-628E-9EE7-E040-000A3E0034B3","111","","","","3","2010","0.001597","1","9/16/2010 11:29:13 AM"]},
{"id":"8F4CEED3-628F-9EE7-E040-000A3E0034B3","cell":["8F4CEED3-628F-9EE7-E040-000A3E0034B3","","","","","3","2010","0.001597","1","9/16/2010 11:29:13 AM"]},
{"id":"8F4CEED3-6337-9EE7-E040-000A3E0034B3","cell":["8F4CEED3-6337-9EE7-E040-000A3E0034B3","111","","","","3","2010","0.013223","1","9/16/2010 11:29:07 AM"]},
{"id":"8F4CEED3-6338-9EE7-E040-000A3E0034B3","cell":["8F4CEED3-6338-9EE7-E040-000A3E0034B3","","","","","3","2010","0.013223","1","9/16/2010 11:29:08 AM"]},
{"id":"8F4CEED3-63E0-9EE7-E040-000A3E0034B3","cell":["8F4CEED3-63E0-9EE7-E040-000A3E0034B3","111","","","","3","2010","0.008352","1","9/16/2010 11:29:17 AM"]},
{"id":"8F4CEED3-63E1-9EE7-E040-000A3E0034B3","cell":["8F4CEED3-63E1-9EE7-E040-000A3E0034B3","","","","","3","2010","0.008352","1","9/16/2010 11:29:17 AM"]}]}

Where have I gone wrong?

+2  A: 

It seems the error is the order of js files. You have to include grid.locale-en.js before jquery.jqGrid.min.js. With the correct order of the JavaScript files your grid can be displayed as following. (I changed only width of some columns and remove deprecated imgpath parameter).

Oleg
this is awesome, you are awesome
Chris McCall