user290043
user290043

Reputation:

Dojo DataGrid Not Showing

In my dojo.xhrGet I have specified this load::

load: function (data) {
    // reset data display containers
    dojo.addClass("search_results", "hide_on_load");
    dojo.byId("search_results_found").innerHTML = "";
    // populate table with new results.
    dojo.byId("search_results_found").innerHTML = "" + data.length + " search result(s) found.";

    // when data is from an XHR request, you must transform it into a store.
    // See: http://stackoverflow.com/questions/2423459/datagrid-in-dojo-with-json-data-from-a-servlet
    var items = dojo.map(data, function (res_row) {
        return {
            'Id': res_row.Id,
            'Name': res_row.Name,
            'VisitType': res_row.VisitType,
            'VisitDate': res_row.VisitDate
        };
    });

    var store = new dojo.data.ItemFileReadStore({
        data: {
            items: items
        }
    });

    var res_layout = [
        {field: 'Id',        name: 'ID',         width: '10%'},
        {field: 'Name',      name: 'Site Name',  width: '50%'},
        {field: 'VisitType', name: 'Visit Type', width: '20%'},
        {field: 'VisitDate', name: 'Visit Date', width: '20%'}
        ];

    // create a new grid:
    var res_grid = new dojox.grid.DataGrid({
        store: store,
        structure: res_layout,
        rowsPerPage: 10
    }, document.createElement('div'));

    // append the new grid to the div "search_results_table":
    dojo.byId("search_results_table").appendChild(res_grid.domNode);

    // Call startup, in order to render the grid:
    res_grid.startup();

    dojo.removeClass("search_results", "hide_on_load");
    standby.hide();
},

And, the html is:

<!-- Search Results Table -->
<div id="search_results" class="hide_on_load">
    <div id="search_results_found"></div>
    <div id="search_results_table"></div>
</div>

At the end of this script, the grid does not show.

I removed the hide_on_load css class selector so that I could exclude it as being the issue. But, that did not help.

Looking at the console, there are no errors logged.

Also, writing the various objects (res_grid, store, etc.) all produce output that looks to be correct.

Can somebody provide some help on how to get it to show?

Thanks!

Update:

When I inspect the DOM after this code has run, I see the tabler created with the headers but then when I go to find the actual table with the search results (under div class=dojoxGridContent), it isn't there.

Update 2:

I have the styles specified too:

<style type="text/css">
    @import "http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/grid/resources/Grid.css";
    @import "http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/grid/resources/claroGrid.css";
    .dojoxGrid table { margin: 0; }
</style>

Upvotes: 1

Views: 4796

Answers (2)

Jay
Jay

Reputation: 61

If you don't want a fix height you can declare the grid withautoHeight: true.

var res_grid = new dojox.grid.DataGrid({

        store: store,
        structure: res_layout,
        rowsPerPage: 10,
        autoHeight: true
    }, document.createElement('div'));

With This attribute you don't need to add style to the parent container for it to display.

Upvotes: 1

Philippe
Philippe

Reputation: 6828

Make sure you set a size through the style property on the div where you place your grid, and don't forget to import the CSS files for your grid, like :

<style type="text/css">
    @import "dojoroot/dojox/grid/resources/Grid.css";
    @import "dojoroot/dojox/grid/resources/soriaGrid.css";

    .dojoxGrid table {
        margin: 0;
    }
</style>

Note : Replace soria by whatever theme you are using...

... and don't forget to set a size to your grid's dom node :

<div id="gridnode" style="width:100%; height:500px;"></div>

Upvotes: 2

Related Questions