PDA

View Full Version : Insert new row for a grid having 0 rows in the beginning



mangesh
13 Nov 2006, 11:33 PM
Hi,

I have problems inserting a row when the existing grid has 0 rows in it. Following is the error I get:

Error: this.data[0] has no properties
Source File: http://localhost/handyman/src/yui-ext.js
Line: 310


Thanks,
Mangesh

jack.slocum
14 Nov 2006, 12:08 AM
Do you have some code?

mangesh
14 Nov 2006, 12:22 AM
This is the function I use for loading initial grid.

loadJournal : function() {
var formatDate = function(value){
return value.dateFormat('M d, Y');
};

// this.sm2 = new YAHOO.ext.grid.EditorSelectionModel();
// this.sm2.clicksToActivateCell = 1;
this.sm2 = new YAHOO.ext.grid.SingleSelectionModel();

var yg = YAHOO.ext.grid;

// create our column model
this.cm2 = new YAHOO.ext.grid.DefaultColumnModel([
{header: "Seq#", width: 45},
{header: "Comment", width: 450, editor: new yg.TextEditor()},
{header: "Entry Date", width: 150},
{header: "Updated By", width: 100}
]);
// instead of setting sortable in every column, we can set the default using this property
this.cm2.defaultSortable = true;

// create the data model. Notice the new "totalTag" schema item. That tells the model which tag to
// look in for the total number of records
this.dm2 = new YAHOO.ext.grid.XMLDataModel({
tagName: 'je',
id: 'id2',
fields: [ 'n_seq', 's_comments', 'd_updated', 'updatedby']
});

// set the additional params we want passed (this could have been passed
// as a third param to initPaging)
this.dm2.setDefaultSort(this.cm2, 0, 'DESC');
// select the first row in the grid every time a new datset is loaded
// this.dm2.addListener('load', this.sm2.selectFirstRow, this.sm2, true);

// create the grid object
this.grid2 = new YAHOO.ext.grid.EditorGrid('je-grid', this.dm2, this.cm2);
this.grid2.render();
this.grid2.autoSize();
this.grid2.addListener('afteredit', onAfterEdit);

var dm = this.dm1;
var sm = this.sm1;

var rows = sm.getSelectedRows();
var row = rows[0];
if( row != undefined ) {
var node = dm.getNode(row.rowIndex);
// Job Id
var jobID = dm.getNamedValue(node, 'k_job');

this.dm2.load("journal.php?k_job=5" + jobID );
}
},


Then I use following function to insert a row. It works fine if the above function populates more than one row in the grid.

newEntry : function( ) {
var dm = this.dm2;
var sm = this.sm2;
var grid = this.grid2;
var today = new Date();

// Job Id
var jobIDElem = YAHOO.util.Dom.get('jobid');
var rowCount = dm.getRowCount();
var insertPos = parseInt( rowCount );
var cellValues = new Array();

cellValues[0] = insertPos+1;
cellValues[1] = "";
cellValues[2] = today.getFullYear() + "-" + today.getMonth() + "-" + today.getDate();
cellValues[3] = YAHOO.util.Dom.get('userName').value;
if ( insertPos > 0 ) {
var rowIndex = dm.insertRow( insertPos, "newRow", cellValues);
} else {
var rowIndex = dm.insertRow( 0, null, cellValues);
}
grid.addListener( 'afteredit', onAfterEdit );

return;
},


Jack, I would like to take this opportunity to thank you very much for doing all this. This is great stuff.

jack.slocum
14 Nov 2006, 2:29 PM
To insert rows dynamically into an XMLDataModel you need to implement the createNode method sometimes. I depends on your documents structure. If you look at my post "Exploring cross-browser xml data binding" it has more details.

jack.slocum
14 Nov 2006, 2:39 PM
To insert rows dynamically into an XMLDataModel you need to implement the createNode method sometimes. I depends on your documents structure. If you look at my post "Exploring cross-browser xml data binding" it has more details.

jack.slocum
14 Nov 2006, 2:39 PM
To insert rows dynamically into an XMLDataModel you need to implement the createNode method sometimes. I depends on your documents structure. If you look at my post "Exploring cross-browser xml data binding" it has more details.

jack.slocum
14 Nov 2006, 2:40 PM
To insert rows dynamically into an XMLDataModel you need to implement the createNode method sometimes. I depends on your documents structure. If you look at my post "Exploring cross-browser xml data binding" it has more details.

jack.slocum
14 Nov 2006, 3:03 PM
Sorry the forum was corrupted, it's fixed now.

jack.slocum
14 Nov 2006, 3:05 PM
Sorry the forum was corrupted, it's fixed now.

jack.slocum
14 Nov 2006, 3:06 PM
Maybe not.

Animal
15 Nov 2006, 12:05 AM
I still I did that multi-post thing last night!

I just saw that SQL error about 5 minutes ago.