DataGrid - specify constraint in markup

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

DataGrid - specify constraint in markup

Rick Lacy
If you define the columns of a grid in markup using table, tr, and th tags, should it be possible for the constraint to be specified on the th tag?  The formatter seems to be recognized, but I haven't had any luck with the constraint.  For example,

		
<html>
	<head>
		<link rel="stylesheet" type="text/css" href="dojo-release-1.6.0-src/dojo/resources/dojo.css" />
		<link rel="stylesheet" type="text/css" href="dojo-release-1.6.0-src/dijit/themes/claro/claro.css" />
		<link rel="stylesheet" type="text/css" href="dojo-release-1.6.0-src/dojox/grid/resources/Grid.css" />
		<link rel="stylesheet" type="text/css" href="dojo-release-1.6.0-src/dojox/grid/resources/claroGrid.css" />
		
		<script type="text/javascript">
			djConfig = {
				parseOnLoad: true,
				isDebug: true,
				debugAtAllCosts: true
			};
		</script>
		
		<script type="text/javascript" src="dojo-release-1.6.0-src/dojo/dojo.js"></script>
		
		<script type="text/javascript">
			dojo.require("dojox.grid.DataGrid");
			dojo.require("dojo.data.ItemFileReadStore");
			
			dojo.addOnLoad(function() {
				var theGreatestTeamOfAllTime = {
					items: [{
						"number" : "12",
						"name" : "Some Guy 1"
					}, {
						"number" : "34",
						"name" : "Some Guy 2"
					}],
					identifier: "number"
				};
				
				var dataStore = new dojo.data.ItemFileReadStore({
					data: theGreatestTeamOfAllTime
				});
				
				var grid = dijit.byId("myGrid");
				grid.setStore(dataStore);
			});
			
			function nameFormatter(value, rowIndex) {
				console.log(value);
				
				//constraint is undefined...
				console.log(this.constraint);
				
				return value;
			}
		</script>
	</head>
	<body class="claro">
		<div style="width:310px; height:200px">
			<table id="myGrid" dojoType="dojox.grid.DataGrid" selectable="true">
				<thead>
					<tr>
						<th field="number" width="100px">Number</th>
						<th field="name" width="200px" formatter="nameFormatter" constraint="{field: 'name'}">Name</th>
					</tr>
				</thead>
			</table>
		</div>
	</body>
</html>
Reply | Threaded
Open this post in threaded view
|

Re: DataGrid - specify constraint in markup

Rick Lacy
Does anyone have an opinion on whether this is a bug or not?  If it's a bug, a like to submit it.  Just wanted to be sure I wasn't overlooking something obvious first...
Reply | Threaded
Open this post in threaded view
|

Re: DataGrid - specify constraint in markup

Eric Pasquier
Hi Rick,
Specifiying the constraint in the th field is the correct way, and it's
working.
Eric.

----- Original Message -----
From: "Rick Lacy" <[hidden email]>
To: <[hidden email]>
Sent: Thursday, May 12, 2011 1:16 PM
Subject: Re: [Dojo-interest] DataGrid - specify constraint in markup


> Does anyone have an opinion on whether this is a bug or not?  If it's a
> bug,
> a like to submit it.  Just wanted to be sure I wasn't overlooking
> something
> obvious first...
>
> --
> View this message in context:
> http://dojo-toolkit.33424.n3.nabble.com/DataGrid-specify-constraint-in-markup-tp2922856p2931359.html
> Sent from the Dojo Toolkit mailing list archive at Nabble.com.
> ________________________________________________________
> Dojotoolkit: http://dojotoolkit.org
> Reference Guide: http://dojotoolkit.org/reference-guide
> API Documentation: http://dojotoolkit.org/api
> Tutorials: http://dojotoolkit.org/documentation
>
> [hidden email]
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>

________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

[hidden email]
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|

Re: DataGrid - specify constraint in markup

Rick Lacy
Hi Eric,

I'm still not sure I understand.  Is the method you're saying different than the one used in the example I provided?  I tried this using dojo 1.6.0 against multiple browsers and this.constraint was always undefined in the formatter.  Could you perhaps point me to a small example of what the correct format is?


Thanks for the assistance,

Rick
Reply | Threaded
Open this post in threaded view
|

Re: DataGrid - specify constraint in markup

Rick Lacy
I spent some more time looking at this and believe I have a better idea of what's going on.  This would have been more obvious if I had more experience with Dojo, but right now the markup parser assumes constraints are tied to editors.  The code that actually parses the constraint attr is in the markupFactory on dojox.grid.cells._Widget.  The markupFactory on dojox.grid.cells._Base doesn't have code to parse the constraint attr.  The example in the original post failed because I had not defined a specific editor for the cell.  Even specifying editable="true" is not enough; the cellType attr must be defined to something.

I do consider this a bug / feature request.  It seems like a valid use case to have a formatter that renders values depending on the row AND column.  The formatter function only receives the value and rowIndex.  The only way to make this happen based on what I know now is to specify data on the constraint.  Moreover, when creating a grid programmatically, it is possible to have a formatter and constraint without an editor.  It seems like there should be consistency between the features of the grid you can access from both methods of creation.

My solution was to add the parsing code to the markupFactory in dojox.grid.cells._Base -

var constraint = d.trim(d.attr(node, "constraint")||"");
if(constraint){
  cellDef.constraint = d.fromJson(constraint);
}


Would it be possible to see this in a future version of Dojo?  What's the protocol for submitting tickets / patches?

Thanks,


Rick