Creating dojo EnhancedGrid using AMD style

I am trying to create enhancedgrid using AMD style but facing issues. I have created a custom build for dojo 1.7.1

The code for Enhancedgrid doesn't give any javascript error. The code I am using is:

<script data-dojo-config="async: true" src='./dojo/dojo.js'></script>
<script data-dojo-config="async: true" src='./dojo/mydojo.js'></script>
<script>

var dojoConfig = {
    baseUrl: "./",
    tlmSiblingOfDojo: false,
    packages: [
        { name: "dojo", location: "dojo" },
        { name: "dijit", location: "dijit" },
        { name: "dojox", location: "dojox" }
    ]
};

define(["dojox/grid/EnhancedGrid","dojo/data/ItemFileWriteStore"], function(EnhancedGrid,ItemFileWriteStore){
        /*set up data store*/
        var data = {
          identifier: 'id',
          items: []
        };
        var data_list = [
          { col1: "normal", col2: false, col3: 'But are not followed by two hexadecimal', col4: 29.91},
          { col1: "important", col2: false, col3: 'Because a % sign always indicates', col4: 9.33},
          { col1: "important", col2: false, col3: 'Signs can be selectively', col4: 19.34}
        ];
        var rows = 60;
        for(var i=0, l=data_list.length; i<rows; i++){
          data.items.push(dojo.mixin({ id: i+1 }, data_list[i%l]));
        }
        var store = ItemFileWriteStore({data: data});

        /*set up layout*/
        var layout = [[
          {'name': 'Column 1', 'field': 'id'},
          {'name': 'Column 2', 'field': 'col2'},
          {'name': 'Column 3', 'field': 'col3', 'width': '230px'},
          {'name': 'Column 4', 'field': 'col4', 'width': '230px'}
    ]];

        /*create a new grid:*/
        var grid = EnhancedGrid({
            id: 'grid',
            store: store,
            structure: layout,
            rowSelector: '20px'
         },  document.createElement('div'));

        /*append the new grid to the div*/
        dojo.byId("gridDiv").appendChild(grid.domNode);

        /*Call startup() to render the grid*/
    grid.startup();
});

</script>

Could some one point the problem area.

Upvotes: 0

Views: 367

Answers (1)

Lucian Depold
Lucian Depold

Reputation: 2019

Main problem:

You use define instead of require function ! Code doesn't get executed !

Second problem:

You pass document.createElement('div') to your grid ! But it expects a div-id !

Here is a working jsfiddle:

http://jsfiddle.net/f8Zm7/1/

Do not add javascript code using only the <script> tag, use

<script type="text/javascript"></script>

Do not forget to close it.

The jsfiddle is missing the css files, so do not expect a good looking grid...

Upvotes: 1

Related Questions