PDA

View Full Version : Please help. Grid not load xml data set!



davy_wei
6 Jan 2007, 8:05 PM
Hi,

I am using a Grid in a BorderLayout center content panel. The code is modified from the example forum.js. You can see the exact problem right here http://www.yr-tech.com:8024/useradmin.php

Here is the Grid code.

<script type="text/javascript">
var DataList=function(){
var grid, dm, cm, sm;
return{
init: function(){
sm=new YAHOO.ext.grid.SingleSelectionModel();

cm=new YAHOO.ext.grid.DefaultColumnModel([
{header:"Name",width:150},
{header:"User ID",width:150},
{header:"Company",width:200},
{header:"Email",width:300}
]);
cm.defaultSortable=true;

dm=new YAHOO.ext.grid.XMLDataModel({
tagName:'User',
totalTag:'TotalCount',
id:'id',
fields:['Name','UserName','Company','Email']
});
dm.initPaging('/useradmin.php',20);
dm.baseParams={'act':'page'};
dm.setDefaultSort(cm,0,'ASC');
dm.addListener('load',sm.selectFirstRow,sm,true);

grid=new YAHOO.ext.grid.Grid('main-body',dm,cm,sm);
grid.render();
dm.loadPage(1);
},

loadDataList: function(){
dm.baseParams={'act':'page'};
dm.loadPage(1);
}
};
}();
YAHOO.ext.EventManager.onDocumentReady(DataList.init, DataList, true);
</script>

Here is what I get from the initPaging PHP execution result. http://www.yr-tech.com:8024/useradmin.php?act=page&page=1&pageSize=20&sortColumn=0&sortDir=ASC
All the passing variables are the same as the set in dm. The return result is an xml file which contains 20 user accounts. When I replace dm.addListener('load',sm.selectFirstRow,sm,true); to dm.addListener('load',alert('bla bla bla')); The alert message is show which means the event load is triggered. However there are nothing showing in the grid except the header column.

The problem is the returned xml dataset are not loaded into the Grid. The Grid column and pagination bar are shown properly, but no data are loaded.

Is there anything wrong in my code? Please help me. I appreciate it.

jack.slocum
6 Jan 2007, 8:14 PM
dm.addListener('load',alert('bla bla bla')); won't tell you anything because it executes the alert immediately (it's not a callback).

The xml document is not being parsed by the browser (responseXML is null, even though I see the XML doc being retreived). Did you set a Content-Type header in your php script?

header('Content-Type: text/xml');