[Dojo-interest] grid sortFields

Maulin Shah maulinpshah at gmail.com
Mon Aug 4 04:32:04 UTC 2008


the closest I can see is to override getSortProps to return your own  
array of sortFields based on the currently sorted cell index (much as  
in the past you could have over-ridden grid.model.sort). but defining  
your inital sort column is set by setting the attribute on your  
declaration of "sortInfo" to your 1-based column index (negative for  
descending).

so --

<table dojoType="dojox.grid.DataGrid" sortInfo="1">
	<thead>
		<tr>
			<th field="name">Name</th>
			<th field="age">Age</th>
		</tr>
	</thead>
	<script type="dojo/method">
		this.getSortProps = function() {
		var c = this.getCell(this.getSortIndex());
		if(!c){
			return null;
		}else{
			var desc = c["sortDesc"];
			var si = !(this.sortInfo>0);
			if(typeof desc == "undefined"){
				desc = si;
			}else{
				desc = si ? !desc : desc;
			}
		
			if (c.field=="name") {
				return [{attribute:"type", descending: desc}, { attribute:  
c.field, descending: desc }];
			} else if (c.field == "age") {
			//todo
			} else { //default
				return [{ attribute: c.field, descending: desc }];
			}
		}
		}
	</script>
</table>

(you could make this even cleaner if you just extend DataGrid to your  
own custom Grid class, then you could use this.inherited() instead of  
repeating a lot of code that is already written)

On Aug 3, 2008, at 5:35 PM, Dylan Tynan wrote:

> I saw that also.  I ended up doing:
>
>               mygrid.setSortIndex(#, false);
>
> where # is the column# to sort on (and doing it after the grid was
> available w/data loaded, of course).  Seems to work, not sure how
> 'right' it is though...
>
> Dylan Tynan
>
> -----Original Message-----
> From: dojo-interest-bounces at dojotoolkit.org
> [mailto:dojo-interest-bounces at dojotoolkit.org] On Behalf Of Maulin  
> Shah
> Sent: Sunday, August 03, 2008 8:40 AM
> To: dojo-interest at dojotoolkit.org
> Subject: [Dojo-interest] grid sortFields
>
> is it me or has sortFields gone away in grid 1.2? the only thing I can
> find in 1.2 is sortInfo (the index of the current column to sort by).
> Is that intentional? sortFields is even in the Mastering Dojo book,  
> so I
> imagined it wasn't going to be removed... thoughts?
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://dojotoolkit.org/docs/book
> Forums: http://dojotoolkit.org/forum
> Dojo-interest at dojotoolkit.org
> http://turtle.dojotoolkit.org/mailman/listinfo/dojo-interest
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://dojotoolkit.org/docs/book
> Forums: http://dojotoolkit.org/forum
> Dojo-interest at dojotoolkit.org
> http://turtle.dojotoolkit.org/mailman/listinfo/dojo-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://turtle.dojotoolkit.org/pipermail/dojo-interest/attachments/20080803/58b8c7e5/attachment.html 


More information about the Dojo-interest mailing list