grid
in onBeforeRow, I need to know what grid I am building. need grid id, or grid object
Posted November 12th, 2008 by torqueaddictI am extending the subgrids example, and in the onBeforeRow, I need to know the grid that I am building. The "this" object is a view. I was hoping from the view I could somehow access the grid but I can't find a way to.
What I really want to do is something like this:
function buildSubgrid(inRowIndex, inCell) {
...
subGrid['info'] = "data";
subGrid.render();
...
}
and, in the onBeforeRow: access data. In onBeforeRow I also tried this.getCell(0,0).grid['info'] but it seems that the cells are undefined.
As an alternative I'd be happy if I could access that view variable and set my data on it, so I can access it in onBeforeRow that way.
thanks for any help!
need help understanding subgrids - ussues with grid height using 3 levels of dojo subgrids
Posted November 9th, 2008 by torqueaddictHi. Firstly, I'd like to better understand the dojo subgrid example. Why do they need to use setTimeout to build the subgrid? How exactly does the cacheHeight work? I see the cacheHeight is the size of the grid just created, but it seems that the div height is 120px because the grid is undefined. Why return the div anyway as a "placeholder"? Should I use autoheight=true for grids / subgrids?
I have a dojo grid, that contains subgrids, like the "subgrid" test example. I am using dojo 1.1.1. My grid has rows that expand to show a subgrid, and that subgrid can expand to show another subgrid.
1st level subgrid works fine, using a paradigm like the subgrid example supplied with dojo. However, the 3rd level was much more complicated. When I got that working I had weird grid height behavior. I would see that the 3rd level grid was created but the main grid height would not update and you can't see the grids.
After studying the problem, I think my issue is that I have variable height subgrids. The example frequently results in using the default "120px". I think the example depends on having the div placeholder set the height for the cell that contains the subgrid. Although I don't completely believe this because the 1st/2nd levels work fine, even when level 2 has many rows, and the div height is always 120 the 1st time!
Any info on this would be greatly appreciated!
Dojox Grid problem this._arrayOfTopLevelItems has no properties
Posted May 9th, 2008 by algu84Hi to all, I'm pretty new to Dojo and I'm experiencing some problems with grids. I need to show data caught from a DB which sends them in JSON format. It's an array containing a number in the first position, and arrays again in the other positions; client side I just group the arrays in bigger ones through some criteria. Each group represents a data store for a single grid.
My problem is that grids show only question marks, instead of data. Through FireBug I had the following error description:
"this._arrayOfTopLevelItems has no properties"
"TypeError"
"(\"{\\"identifier\\":\\"Id\\",\\"items\\":[{\\"machine_id\\":1,\\"machine_line_id\\":1,\\"machine_name\\":\\"blowing machine\\",\\"machine_xml_file_path\\":\\"/etc/drupal/blower.xml\\",\\"machine_ip_address\\":\\"127.0.0.1\\",\\" ...
I tried to follow many examples, with multiple data model, but I didn't reach my goal
Here is part of the data I get after the dojo.toJson(dataobj) call and my JS code. Thanks in advance for your help.
{"identifier":"Id","items":[{"machine_id":1,"machine_line_id":1,"machine_name":"blowing machine","machine_xml_file_path":"/etc/drupal/blower.xml","machine_ip_address":"127.0.0.1","machine_nominal_speed":20000,"machine_type_id":1,"machine_is_configured":true,"machine_position":1,"machine_image_path":"/prova","machine_port":50000,"machine_driver_path":"/home/clsv/workspace/communicator/Debug/communicator"}... ]}
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dojox.grid.Grid");
dojo.require("dojo.parser");
dojo.require("dojox.grid._data.model");
function handleError(response,xhr)
{
alert("An error has occurred:\nRefresh your page and try again");
console.debug(response);
}
function buildGrid(response,xhr)
{
// we must treat data in order to convert them from string to number, boolean, ...
for (i = 2; i < response.length; i++)
{
response[i]['machine_id'] = Number(response[i]['machine_id']);
response[i]['machine_line_id'] = Number(response[i]['machine_line_id']);
response[i]['machine_nominal_speed'] = Number(response[i]['machine_nominal_speed']);
response[i]['machine_type_id'] = Number(response[i]['machine_type_id']);
response[i]['machine_is_configured'] = "t"?response[i]['machine_is_configured']= true:response[i]['machine_is_configured']= false;
response[i]['machine_position'] = Number(response[i]['machine_position']);
response[i]['machine_port'] = Number(response[i]['machine_port']);
}
// First of all we have to create an array containing machines' data divided by lines
var lines = new Array(); // this array will contain the array of each line
for (i = 1; i <= response[0]; i++) // tried to do it server-side, but a sort of overflow exception was thrown
{
var linedata = new Array(); // this array will contain the data of all machines in one line
for (j = 2; j < response.length; j++) // We start from the third position of response because the previous two are for number of lines and machine types
{
if (response[j]['machine_line_id'] == i) // if the line_id of the machine is the one we are treating
linedata.push(response[j]);
}
lines.push(linedata);
}
for (i = 1; i <= response[0]; i++)
{
//Data
var j = i-1;
var dataobj = {};
dataobj.identifier = 'Id';
dataobj.items = lines[j];
//Store
var store = new dojo.data.ItemFileReadStore({jsId: 'jsonStore',data: dojo.toJson(dataobj)});
//Model
//var model = new dojox.grid.data.Table(null, dojo.toJson(lines[j]));
var model = new dojox.grid.data.DojoData(null, store, {jsId: 'model', query:{ id : '*' },clientSort:true});
//Structure
gridLayout = [
{cells: [[
{ name: 'Id'},
{ name: 'Line id'},
{ name: 'Machine name', styles: 'text-align: center;'},
{ name: 'DDF path', styles: 'text-align: center;'},
{ name: 'IP address', styles: 'text-align: center;'},
{ name: 'Nominal speed', styles: 'text-align: center;'},
{ name: 'Type', styles: 'text-align: center;'},
{ name: 'Is configured', styles: 'text-align: center;'},
{ name: 'Position', styles: 'text-align: center;'},
{ name: 'Image path', styles: 'text-align: center;'},
{ name: 'Port', styles: 'text-align: center;'},
{ name: 'Driver path', styles: 'text-align: center;'},
]]}];
dojo.byId("datacontainer").innerHTML += "..."; // here I add some element to the DOM, buttons, ...
var gridContainer = dojo.byId("datacontainer").appendChild(document.createElement("div"));
var str = "grid" + i; var grid = new dojox.Grid({ id: str, model: model, structure: gridLayout, autoHeight: true, autoWidth: true }, gridContainer); }
grid.startup();
}
var xhrparam = { url: "initlinemach.php", load: buildGrid, error: handleError, handleAs: "json", timeout: 4000 };
dojo.xhrGet(xhrparam);
Dynamic grid layout structure
Posted January 16th, 2008 by dsotosekHi all!
How can I create dynamic grid layout structure based on structure defined in database table?
for example:
1.) have a table A. In it are only table names of tables for which I want to make grids
2.) I want to take "show columns for chosen table" the column names and column data types and upon them dinamically create layout cell structure.
Bellow is example of hard coded layout structure from dojo grid test example. What I want is to dynamically fill the cell array of columns structure from db table;
var gridLayout = [
{ type: "dojox.GridRowView", width: "20px" },
{ defaultCell: { width: 6, editor: dojox.grid.editors.Dijit },
cells: [[
{ name: 'Id', styles: 'text-align: right;', editorClass: "dijit.form.NumberTextBox" },
{ name: 'Name', width: 20},
{ name: 'Message', styles: 'text-align: right;'},
{ name: 'Date',
editor: mySqlDateEditor,
formatter: formatMySqlDate,
constraint: {selector: "date"},
width: 10,
styles: 'text-align:right;'}
]]
}
];
Thank you in Advance,
David
Dynamic grid renders blank rows
Posted January 1st, 2008 by CDHMBI created a grid dynamically using the following code snippet:
var placeHolder = document.createElement("div");
dojo.byId("browse").appendChild(placeHolder);
var grid = new dojox.Grid({id: "grid", model: ddata, structure: layout2}, placeHolder);
grid.setModel(ddata);
grid.setStructure(layout);
grid.startup();
grid.model.store has 36 data items, so the data/model seem to be populated, but the grid renders blank rows with the table headings ok. The fields in the layout/view seem to be right. Any ideas? Thanks tons for the help.
Dojo Forum