views:

1535

answers:

1

I want a dojox.grid.DataGrid with a dojo.data.ItemFileReadStore as the data store. I want it to fill the entire screen. I don't want to specify dimensions in pixels. All the examples that I've seen specify them in pixels or use a CSV data store. I've tried using HTML elements and javascript to setup the datagrid and store.

Has anyone done this? Is there a bug? It seems like what anyone would want, but maybe it's not possible for some reason. Any ideas? Thanks!

Edit to insert code:

<div id="gridContainer" style="width: 100%; height: 100%;"></div>

<div id="gridContainer1" style="width: 400px; height: 200px;"></div>


<script type="text/javascript">

    dojo.addOnLoad(function(){
        // our test data store for this example:
        var jsonStore = new dojo.data.ItemFileReadStore({
            url: '/mydata.json'
        });

        var layout = [{
            field: 'id',
            name: 'id',
            width: '20px'
        },
        {
            field: 'name',
            name: 'name',
            width: '50px'
        },
        {
            field: 'owner',
            name: 'owner',
            width: '50px'
        }];

        // create a new grid:
        var grid = new dojox.grid.DataGrid({
            query: {
            rowid: '*'
            },
            store: jsonStore,
            clientSort: true,
            rowSelector: '20px',
            structure: layout
        },
        document.createElement('div'));

        dojo.byId("gridContainer1").appendChild(grid.domNode);

        grid.startup();
    });
</script>

Depending on whether I use gridContainer or gridContainer1, it does not show or shows the grid respectively.

What gives?

A: 
Andy
Hi Andy, thanks for the explanation. Just to confirm:There is no default width for columns? If I specify them via the "layout", then I can specify my container element to 100% wide and 100% high(no pun intended). Right now I do have a container element, but the odd thing is that what affects the width seems to be if I specify a width for the div that defines the dojo.data.ItemFileReadStore - not the container.My grid's columns are dynamic. The number and their contents are determined by data from a database. So if I specify the same width for each, I guess that is fine. I'll give it a try.
Sims
I edited my question to include my code example. I've also tried it without document.createElement('div') and dojo.byId("gridContainer").appendChild(grid.domNode). Still the same problem. The container div with percentage dimensions shows nothing. While the container div pixel dimensions shows everything. Also another thing I found strange is that span elements can be used with csv data stores and but not with json. I'm specifying a 'url' for my store. I'm not keen on recreating it via javascript.
Sims
It seems the width can be 100% - not a pixel value, but height must be a pixel value.
Sims
It's really a CSS/HTML issue. The parent element of the ContentPane must have a value - even 100%. So the body element must also have a value of 100%, which messes up a lot of margins and the like. Looks like I'm going to have to rebuild the layout of my app to work with this. Thanks for your help Andy.
Sims
My single page RIA uses:<div class="app"></div>where the css has :.app{width:100%;height:100%;overflow:hidden;padding:0;margin:0;}You can add padding and margins to contained elements, but the above is a pretty standard single page container div.In markup you could add a ContainerPane and set its style to be width and height 100% and then when creating the grid do:<div class="app"> <div dojoAttachPoint="gridPlaceholder"></div></div>and use the previous code I mention.
Andy