Drahcir
Drahcir

Reputation: 12621

Unable to load XML data in jqGrid

I am using jqGrid of which I downloaded from here http://www.trirand.com/blog . I followed the tutorial word by word to test out the grid. Now the alterations I did is that the page from which the grid gets the data is in asp.net instead of php.

The problem is that the grid loads fine and there is a response with the xml data that I generated but for some reason isnt being loaded on the grid itself (ie im left with a blank grid.

The code that i used is

<link rel="stylesheet" type="text/css" media="screen" href="js/themes/basic/grid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="js/themes/jqModal.css" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.js" type="text/javascript"></script>
<script src="js/js/jqModal.js" type="text/javascript"></script>
<script src="js/js/jqDnR.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function(){ 
  jQuery("#list").jqGrid({
    url:'nrGetjqgridXML.aspx',
    datatype: "xml",      
    colNames:['Dummy ID','Dummy String','Dummy Int','Dummy Char','Dummy Bool','Dummy Date','Dummy Float'],colModel :[{name:'dummyID', index:'dummyID' , width:100, sortable:true},{name:'dummyString', index:'dummyString' , width:100, sortable:true},{name:'dummyInt', index:'dummyInt' , width:100, sortable:true},{name:'dummyChar', index:'dummyChar' , width:100, sortable:true},{name:'dummyBool', index:'dummyBool' , width:100, sortable:true},{name:'dummyDate', index:'dummyDate' , width:100, sortable:true},{name:'dummyFloat', index:'dummyFloat' , width:100, sortable:true}],                    
    rowNum: 10,
    rowList:[10,20,30],
    imgpath: 'js/themes/basic/images',
    pager: jQuery('#pager'),
    sortname: 'dummyid',   
    viewrecords: true,
    sortorder: "desc",    
    caption: 'Test Grid'
  }).navGrid('#pager', {edit:false , add:false, del:false}); 
}); 
</script>

and this is the response of nrGetjqgridXML :

<xml version='1.0' encoding = 'utf-8'?>
<rows>
   <page>1</page>
   <total>2</total>
   <records>15</records >
   <row id = '15'>
      <cell>15</cell>
      <cell><![CDATA[Test15]]></cell>
      <cell>15</cell>
      <cell><![CDATA[o]]></cell>
      <cell><![CDATA[False]]></cell>
      <cell>15/03/2005 00:00:00</cell>
      <cell>15.15</cell>
   </row>
   <row id = '14'>
      <cell>14</cell>
      <cell><![CDATA[Test14]]></cell>
      <cell>14</cell>
      <cell><![CDATA[n]]></cell>
      <cell><![CDATA[False]]></cell>
      <cell>14/02/2004 00:00:00</cell>
      <cell>14.14</cell>
   </row><row id = '13'>
      <cell>13</cell>
      <cell><![CDATA[Test13]]></cell>
      <cell>13</cell>
      <cell><![CDATA[m]]></cell>
      <cell><![CDATA[True]]></cell>
      <cell>13/01/2003 00:00:00</cell>
      <cell>13.13</cell>
   </row>
   <row id = '12'>
      <cell>12</cell>
      <cell><![CDATA[Test12]]></cell>
      <cell>12</cell>
      <cell><![CDATA[l]]></cell>
      <cell><![CDATA[False]]></cell>
      <cell>12/12/2002 00:00:00</cell>
      <cell>12.12</cell>
   </row><row id = '11'>
      <cell>11</cell>
      <cell><![CDATA[Test11]]></cell>
      <cell>11</cell>
      <cell><![CDATA[k]]></cell>
      <cell><![CDATA[True]]></cell>
      <cell>11/11/2001 00:00:00</cell>
      <cell>11.11</cell>
   </row>
   <row id = '10'>
      <cell>10</cell>
      <cell><![CDATA[Test10]]></cell>
      <cell>10</cell>
      <cell><![CDATA[j]]></cell>
      <cell><![CDATA[False]]></cell>
      <cell>10/10/2000 00:00:00</cell>
      <cell>10.1</cell>        
   </row>
   <row id = '9'>
      <cell>9</cell>
      <cell><![CDATA[Test9]]></cell>
      <cell>9</cell>
      <cell><![CDATA[i]]></cell>
      <cell><![CDATA[False]]></cell>
      <cell>09/09/1999 00:00:00</cell>
      <cell>9.9</cell>
   </row>
   <row id = '8'>
       <cell>8</cell>
       <cell><![CDATA[Test8]]></cell>
       <cell>8</cell>
       <cell><![CDATA[h]]></cell>
       <cell><![CDATA[False]]></cell>
       <cell>08/08/1998 00:00:00</cell>
       <cell>8.8</cell>
   </row>
   <row id = '7'>
       <cell>7</cell>
       <cell><![CDATA[Test7]]></cell>
       <cell>7</cell>
       <cell><![CDATA[g]]></cell>
       <cell><![CDATA[True]]></cell>
       <cell>07/07/1997 00:00:00</cell>
       <cell>7.7</cell>
   </row>
   <row id = '6'>
       <cell>6</cell>
       <cell><![CDATA[Test6]]></cell>
       <cell>6</cell>
       <cell><![CDATA[f]]></cell>
       <cell><![CDATA[True]]></cell>
       <cell>06/06/1996 00:00:00</cell>
       <cell>6.6</cell>
   </row>
   <row id = '5'>
       <cell>5</cell>
       <cell><![CDATA[Test5]]></cell>
       <cell>5</cell>
       <cell><![CDATA[e]]></cell>
       <cell><![CDATA[False]]></cell>
       <cell>05/05/1995 00:00:00</cell>
       <cell>5.5</cell>
   </row>
    <row id = '4'>
       <cell>4</cell>
       <cell><![CDATA[Test4]]></cell>
       <cell>4</cell>
       <cell><![CDATA[d]]></cell>
       <cell><![CDATA[True]]></cell>
       <cell>04/04/1994 00:00:00</cell>
       <cell>4.4</cell>
   </row>
   <row id = '3'>
       <cell>3</cell>
       <cell><![CDATA[Test3]]></cell>
       <cell>3</cell>
       <cell><![CDATA[c]]></cell>
       <cell><![CDATA[False]]></cell>
       <cell>03/03/1993 00:00:00</cell>
       <cell>3.3</cell>
   </row>
   <row id = '2'>
       <cell>2</cell>
       <cell><![CDATA[Test2]]></cell>
       <cell>2</cell>
       <cell><![CDATA[b]]></cell>
       <cell><![CDATA[False]]></cell>
       <cell>02/02/1992 00:00:00</cell>
       <cell>2.2</cell>
   </row>
   <row id = '1'>
       <cell>1</cell>
       <cell><![CDATA[Test1]]></cell>
       <cell>1</cell>
       <cell><![CDATA[a]]></cell>
       <cell><![CDATA[True]]></cell>
       <cell>01/01/1991 00:00:00</cell>
       <cell>1.1</cell>
   </row>
</rows>

This is how the grid is showing up : alt text http://img132.imageshack.us/img132/6671/testgridol7.jpg

Upvotes: 1

Views: 12189

Answers (7)

subbarao sista
subbarao sista

Reputation: 11

You need to use XML Reader for it:

function fillGridOnEvent() {
            $("#jQGrid").html("<table id=\"list\"></table><div id=\"page\"></div>");
            jQuery("#list").jqGrid({
                url: "<URL from where u r getting xml>",
                datatype: "xml",`enter code here`
                height: 250,
                colNames: ['ID', 'Name', 'Sales Rep', 'Market', 'Station', 'Advister', 'Agency'],


                colModel: [{ name: 'id', xmlmap: 'id', width: 75 },
                               { name: 'product_name', xmlmap: 'product_name', width: 190 },
                               { name: 'salesrep_name', xmlmap: 'salesrep_name', width: 100 },
                               { name: 'account', xmlmap: 'account', width: 180, align: "right" },
                               { name: 'station', xmlmap: 'station', width: 180, align: "right" },
                               { name: 'advertiser_name', xmlmap: 'advertiser_name', width: 180 },
                               { name: 'agency_name', xmlmap: 'agency_name', width: 150, sortable: false}],
                xmlReader: {
                    root: "orders",
                    row: "order",
                    page: "orders>page",
                    total: "orders>total",
                    records: "orders>records",
                    repeatitems: false
                },
                multiselect: false,
                paging: true,
                rowNum: 10,
                rowList: [10, 20, 30],
                pager: $("#page"),
                loadonce: true,
                caption: "Student Details"
            }).navGrid('#page', { edit: false, add: false, del: false });

            jQuery().ready(function () {
                //fillGrid();
            });
        }

Upvotes: 1

Marco
Marco

Reputation:

I have same error in Java/Struts, I resolve it, setting a stream of XML, but

public class AtualizarListaAction extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {

        //use this
        response.setContentType("text/xml;charset=utf-8");

        response.getWriter().println(" <rows>");
        response.getWriter().println("  <row id='1' >");            
        response.getWriter().println("   <cell>1</cell>");       
        ...

Upvotes: 0

dario
dario

Reputation: 1

I have tried your code. It works, the only problem I have found is that your XML has one mistake:

The first line must be

<?xml version='1.0' encoding = 'utf-8'?>

instead of

<xml version='1.0' encoding = 'utf-8'?>

Upvotes: 0

rusinak
rusinak

Reputation:

I was running into the same problem. Eventually through trial-and-error, I got it to work by adding:

mtype: 'GET'

as grid option. IE, from your example,

jQuery(document).ready(function(){ 
  jQuery("#list").jqGrid({
        url:'nrGetjqgridXML.aspx',
        datatype: "xml",
        mtype: 'GET',
        ...

Upvotes: 0

angelo
angelo

Reputation:

add

response.setContentType("text/xml;charset=utf-8");

it solves IE problem in updating the grid after servlet response

Thank you

Upvotes: 0

Daniel Moura
Daniel Moura

Reputation: 7966

Have you added?

<table id="list" class="scroll" cellpadding="0" cellspacing="0"></table>

Upvotes: 0

Christian Payne
Christian Payne

Reputation: 7169

Have you added:

<script src="grid/js/jqDnR.js" type="text/javascript">
</script>

Also, your XML is missing the closing

</rows>

tag. Try that!

Upvotes: 1

Related Questions