user550738
user550738

Reputation:

help running simple Ext JS example?

I downloaded Ext JS 4.0.2a and I'm trying to do the Ext JS tutorial. I go the "essentials" example working, so I'm pretty sure I'm set up right. I'm trying to do the grid example here ...

http://www.sencha.com/learn/legacy/Tutorial:Getting_Productive

... but I can't get the grid to display.

My ExtStart.html looks like this:

<html>
<head>
    <title>Introduction to Ext 2.0: Starter Page</title>

    <!-- Include Ext and app-specific scripts: -->
    <script type="text/javascript" src="../adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="../ext-all-debug.js"></script>
    <script type="text/javascript" src="ExtStart.js"></script>

    <!-- Include Ext stylesheets here: -->
    <link rel="stylesheet" type="text/css" href="../resources/css/ext-all.css">
    <link rel="stylesheet" type="text/css" href="ExtStart.css">
</head>
<body>

    <div id="grid-example"></div>

</body>
</html>

and my ExtStart.js is exactly like on the tutorial site like this:

Ext.onReady(function() {
    // sample static data for the store
    var myData = [['Apple',29.89,0.24,0.81,'9/1 12:00am'],
        ['Ext',83.81,0.28,0.34,'9/12 12:00am'],
        ['Google',71.72,0.02,0.03,'10/1 12:00am'],
        ['Microsoft',52.55,0.01,0.02,'7/4 12:00am'],
        ['Yahoo!',29.01,0.42,1.47,'5/22 12:00am']
    ];

    // create the data store
    var ds = new Ext.data.ArrayStore({
        fields: [
           {name: 'company'},
           {name: 'price', type: 'float'},
           {name: 'change', type: 'float'},
           {name: 'pctChange', type: 'float'},
           {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
        ]
    });

    // manually load local data
    ds.loadData(myData);

    // create the colum Manager
    var colModel = new Ext.grid.ColumnModel([
            {header: 'Company', width: 160, sortable: true, dataIndex: 'company'},
            {header: 'Price', width: 75, sortable: true, dataIndex: 'price'},
            {header: 'Change', width: 75, sortable: true, dataIndex: 'change'},
            {header: '% Change', width: 75, sortable: true, dataIndex: 'pctChange'},
            {header: 'Last Updated', width: 85, sortable: true,
                renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
    ]);


    // create the Grid
    var grid = new Ext.grid.GridPanel({
        store: ds,
        colModel: colModel,
        height: 300,
        width: 600,
        title: 'My First Grid'
    });

    // render the grid to the specified div in the page
    grid.render('grid-example');
});

Any ideas what I could be doing wrong? Sadly stumped. :(

rob

Upvotes: 2

Views: 4358

Answers (1)

Amol Katdare
Amol Katdare

Reputation: 6760

You are using ExtJS4 but are referring to a legacy documentation.

There have been quite a few changes to the components and how they need to be wired together between the version that document was written for and version 4 that you are using.

Here is the array grid (and other) example(s) for ExtJS 4. -

HTML
Javascript code

For example, you are using Ext.grid.GridPanel. This is no longer valid. (Use Ext.grid.Panel instead)

Upvotes: 4

Related Questions