jqgrid sample using array data, what am I missing

34,127

Solution 1

Ah, its a damn typo in the Demo code.

The array that is declared is called mydata, and the array in the loop is mydata1[..] (note that evil 1)

grid.locale-en has to be declared first! Then the Browser's debugger can tell you.

(more 'bugyi's, I have some strange Loading text on the top and a striped gray background.)

Solution 2

You are trying to use a pager when you have not set the pager other needed info like the number of rows and page number. Your loop runs into problems when it can't figure out the values for these variables.

Solution 3

This are the css and js to include that do the trick for me. Very important to include grid.base.js

Solution 4

I think the problem is in the colModel somehow. Check if the script after colModel runs. Take only colModel out and then check again. I'm also having this problem at the moment.

example:

jQuery("#appGrid").jqGrid({
    datatype: "local", //or clientSide
    colNames: ["Patient"],
    colModel:[{name:'pat',index:'pat'}]
});

*some code* <- won't run

No wonder the loop doesn't work if the grid won't let you execute code after.

But when I do this:

jQuery("#appGrid").jqGrid({
    datatype: "local", //or clientSide
    colNames: ["Patient"]
});

*some code* <- will run after col error message

The Grid builds just fine, but the code after it isn't executed at all. I don't know where the error is.

Share:
34,127
Dennis
Author by

Dennis

Updated on July 09, 2022

Comments

  • Dennis
    Dennis almost 2 years

    I'm new in jqgrid, I'm just trying thes example to work. I have a html file only, nothing more. When I ran this file, array data is not showing. What am I missing here? Thanks in advance.

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>jqGrid Demos</title>
        <link rel="stylesheet" type="text/css" media="screen" href="lib/jquery-ui-1.7.1.custom.css" />
        <link rel="stylesheet" type="text/css" media="screen" href="lib/ui.jqgrid.css" />
        <link rel="stylesheet" type="text/css" media="screen" href="lib/ui.multiselect.css" />
        <style type="text/css">
            html, body {
                margin: 0;   /* Remove body margin/padding */
                padding: 0;
                overflow: hidden; /* Remove scroll bars on browser window */
                font-size: 75%;
            }
            /*Splitter style */
    
    
            #LeftPane {
                /* optional, initial splitbar position */
                overflow: auto;
            }
            /*
             * Right-side element of the splitter.
            */
    
            #RightPane {
                padding: 2px;
                overflow: auto;
            }
            .ui-tabs-nav li {position: relative;}
            .ui-tabs-selected a span {padding-right: 10px;}
            .ui-tabs-close {display: none;position: absolute;top: 3px;right: 0px;z-index: 800;width: 16px;height: 14px;font-size: 10px; font-style: normal;cursor: pointer;}
            .ui-tabs-selected .ui-tabs-close {display: block;}
            .ui-layout-west .ui-jqgrid tr.jqgrow td { border-bottom: 0px none;}
            .ui-datepicker {z-index:1200;}
        </style>
        <script src="lib/jquery-1.4.2.js" type="text/javascript"></script>
        <script src="lib/jquery-ui-1.7.2.custom.min.js" type="text/javascript"></script>
        <script src="lib/jquery.layout.js" type="text/javascript"></script>
        <script src="lib/grid.locale-en.js" type="text/javascript"></script>
        <script src="lib/jquery.jqGrid.min.js" type="text/javascript"></script>
        <script src="lib/jquery.tablednd.js" type="text/javascript"></script>
        <script src="lib/jquery.contextmenu.js" type="text/javascript"></script>
        <script src="lib/ui.multiselect.js" type="text/javascript"></script>
        <script type="text/javascript">
            // We use a document ready jquery function.
            jQuery(document).ready(function(){
                jQuery("#list").jqGrid({
                    datatype: "local",
                    height: 250,
                    colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total', 'Notes'],
                    colModel:[
                        {name:'id',index:'id', width:60, sorttype:"int"},
                        {name:'invdate',index:'invdate', width:90, sorttype:"date"},
                        {name:'name',index:'name', width:100},
                        {name:'amount',index:'amount', width:80, align:"right",sorttype:"float"},
                        {name:'tax',index:'tax', width:80, align:"right",sorttype:"float"},
                        {name:'total',index:'total', width:80,align:"right",sorttype:"float"},
                        {name:'note',index:'note', width:150, sortable:false}
                    ],
                    pager: '#pager',
                    rowNum:10,
                    rowList:[10,20,30],
                    sortname: 'id',
                    sortorder: 'desc',
                    viewrecords: true,
                    multiselect: true,
                    imgpath: "lib/basic/images",
                    caption: "Manipulating Array Data"
                });
            });
            var mydata = [
                {id:"1",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
                {id:"2",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
                {id:"3",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
                {id:"4",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
                {id:"5",invdate:"2007-10-05",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
                {id:"6",invdate:"2007-09-06",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
                {id:"7",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
                {id:"8",invdate:"2007-10-03",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
                {id:"9",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"}
            ];
            for(var i=0;i<=mydata.length;i++)
                jQuery("#list").jqGrid('addRowData',i + 1, mydata1[i]);
        </script>
    </head>
    <body>
        <table id="list" class="scroll"></table>
        <div id="pager" class="scroll" style="text-align:center;"></div>
    </body>
    
  • Dennis
    Dennis about 14 years
    i can't seem to make this sample to work. i redo my project and followed the jqgrid folder structure as per secondpersonplural.ca/jqgriddocs/index.htm instruction (under introduction-->installation). if it's not a big job for you, would you be able to give me the correct running html and its prerequisite js files? no php files please. just simply the html file with javascript in it is enough. if i can make this array to work, i will continue my study on json. thanks in advance.