dojox.Grid.markupFactory
dojo.require("dojox.grid.Grid");
defined in dojox/grid/Grid.js
Usage
function (props, node, ctor) (view source)
var d = dojo; var widthFromAttr = function(n){ var w = d.attr(n, "width")||"auto"; if((w != "auto")&&(w.substr(-2) != "em")){ w = parseInt(w)+"px"; } return w; } if(!props.model && d.hasAttr(node, "store")){ // if a model isn't specified and we point to a store, assume // we're also folding the definition for a model up into the // inline ctor for the Grid. This will then take properties // like "query", "rowsPerPage", and "clientSort" from the grid // definition. var mNode = node.cloneNode(false); d.attr(mNode, { "jsId": null, "dojoType": d.attr(node, "dataModelClass") || "dojox.grid.data.DojoData" }); props.model = d.parser.instantiate([mNode])[0]; } // if(!props.model){ console.debug("no model!"); } // if a structure isn't referenced, do we have enough // data to try to build one automatically? if( !props.structure && node.nodeName.toLowerCase() == "table"){ // try to discover a structure props.structure = d.query("> colgroup", node).map(function(cg){ var sv = d.attr(cg, "span"); var v = { noscroll: (d.attr(cg, "noscroll") == "true") ? true : false, __span: (!!sv ? parseInt(sv) : 1), cells: [] }; if(d.hasAttr(cg, "width")){ v.width = widthFromAttr(cg); } return v; // for vendetta }); if(!props.structure.length){ props.structure.push({ __span: Infinity, cells: [] // catch-all view }); } // check to see if we're gonna have more than one view // for each tr in our th, create a row of cells d.query("thead > tr", node).forEach(function(tr, tr_idx){ var cellCount = 0; var viewIdx = 0; var lastViewIdx; var cView = null; d.query("> th", tr).map(function(th){ // what view will this cell go into? // NOTE: // to prevent extraneous iteration, we start counters over // for each row, incrementing over the surface area of the // structure that colgroup processing generates and // creating cell objects for each <th> to place into those // cell groups. There's a lot of state-keepking logic // here, but it is what it has to be. if(!cView){ // current view book keeping lastViewIdx = 0; cView = props.structure[0]; }else if(cellCount >= (lastViewIdx+cView.__span)){ viewIdx++; // move to allocating things into the next view lastViewIdx += cView.__span; lastView = cView; cView = props.structure[viewIdx]; } // actually define the cell from what markup hands us var cell = { name: d.trim(d.attr(th, "name")||th.innerHTML), field: d.trim(d.attr(th, "field")||""), colSpan: parseInt(d.attr(th, "colspan")||1) }; cellCount += cell.colSpan; cell.field = cell.field||cell.name; cell.width = widthFromAttr(th); if(!cView.cells[tr_idx]){ cView.cells[tr_idx] = []; } cView.cells[tr_idx].push(cell); }); }); // console.debug(dojo.toJson(props.structure, true)); } return new dojox.Grid(props, node);
parameter | type | description |
---|---|---|
props | ||
node | ||
ctor |