PDA

View Full Version : this.dataModel has no properties



danvega
20 Oct 2006, 3:06 PM
I am getting that error when running the following code and I was just wondering if someone can explain why.

error-this.dataModel has no properties

<DOCTYPE>
<html>
<head>
<title>Grid Component 3</title>
<meta>
<css>
<link>
<yahoo>
<script></script>
<script></script>
<script></script>
<script></script>
<script></script>
<yahoo>
<script></script>
<javascipt>
<script>
function init() {
//initialize the data table component
initDataTable();
}
function initDataTable() {
// data
var rows = [
["John","Smith",28],
["Larry","Johnson",24],
["Howard","Stern",52]
];
// dataModel
var dm = YAHOO.ext.grid.DefaultDataModel(rows);

var sort = YAHOO.ext.grid.DefaultColumnModel.sortTypes;
// columns
var cols = [
{header: "First Name", sortable:true, sortType: sort.asUCString},
{header: "Last Name", sortable:true, sortType: sort.asUCString},
{header: "Age", sortable:true, sortType: sort.asInt}
];
// column model
var cm = YAHOO.ext.grid.DefaultColumnModel(cols);

//constructor
this.grid = new YAHOO.ext.grid.Grid('contactList', dm, cm);
this.grid.render();
}
// on load event handler
YAHOO.util.Event.on(window, "load", init);
</script>
</head>
<body>

<div></div>

</body>
</html>

jack.slocum
20 Oct 2006, 3:52 PM
You are using this within a function that wasn't called with new. Take a look at the example posts on my blog for an idea of how to call it within an object (or you could remove the this).

danvega
20 Oct 2006, 4:02 PM
Thanks, I just figured it out.