PDA

View Full Version : Grid adding empty row



simon.vaillancourt
20 Aug 2007, 6:14 AM
I've encountered a weird problem with a grid.
My XML document contains 2 elements but when the grid is rendered, i have 4 rows.
The first one contains my first element.
The second one contains an empty row.
The third one contains my second element.
The fourth one contains an empty row.

I cannot figure out what the problem is.
Any help would be appreciated.

Note : I obviously renamed some fields in my post, I've check 23 times and they are good. So if some fields do not have the same name, it's a typo in my post.


**** My XML ****
<?xml version="1.0" encoding="UTF-8"?>
<notesList>
<note>
<noteId>54776649</noteId>
<typeCode>GENERAL</typeCode>
<note>first test</note>
<displayInClientViewFlag>false</displayInClientViewFlag>
</note>
<note>
<noteId>2739299251</noteId>
<typeCode>GENERAL</typeCode>
<note>test 123</note>
<displayInClientViewFlag>true</displayInClientViewFlag>
</note>
</notesList>
****************

**** My grid definition ****
init : function(){

// create the Data Store
notesGridDs = new Ext.data.Store({
// load using HTTP
proxy: new Ext.data.HttpProxy({url:'/replaced-url.php'}),

// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have an "note" tag
record: 'note'

}, [
// set up the fields mapping into the xml doc
'noteId','typeCode','note', 'displayInClientViewFlag'
])
});

var cm = new Ext.grid.ColumnModel([
{header: "Type", width: 100, dataIndex: 'typeCode'},
{header: "Note", width: 495, dataIndex: 'note'},
{header: "Display", width: 90, dataIndex: 'displayInClientViewFlag'},
]);
cm.defaultSortable = true;

// create the notesGrid
notesGrid = new Ext.grid.Grid('notes-grid', {
ds: notesGridDs,
cm: cm,
autoSizeColumns:false,
autoSizeHeaders:false
});

// make the grid resizable, do before render for better performance
var rz = new Ext.Resizable('notes-grid', {
wrap:true,
minHeight:100,
pinned:true,
handles: 'all'
});
rz.on('resize', notesGrid.autoSize, notesGrid);

notesGrid.addListener("rowdblclick", notesEdit.rowClicked);
notesGrid.render();

//debugger;
var clientId = getURLParam("clientId");
notesGridDs.load({params:{clientId: clientId}});

//**********Button Listeners*******************************

//edit button
Ext.get("edit").on('click',notesEdit.rowClicked);
Ext.get("add").on('click',notesEdit.addClientNote);
Ext.get("delete").on('click',notesEdit.deleteClientNote);

...
...
...
*****************************

Animal
20 Aug 2007, 6:20 AM
There are 4 <note> elements. Only 2 have the mapped nodes that you asked the Reader to extract. Look at your XML.

simon.vaillancourt
20 Aug 2007, 6:40 AM
Indeed that was the problem.
I've would never have thought that child node with the same name as their parent Node would be mapped too.

Thanks Animal, it works now.