views:

674

answers:

2

I have a DataGrid that is loaded from an XML data store, all created declaratively. I'd like to set the sort when the data is loaded. All of the examples I've found deal with doing this programatically and hint that it should be doable Declaratively.

This is the code that creates the datasource.

<head>
    <title>Untitled Page</title>
    <style type="text/css">
        @import "StyleSheet.css";
        @import "js/dojotoolkit/dijit/themes/pfga/pfga.css";
        @import "js/dojotoolkit/dojo/resources/dojo.css";
        @import "js/dojotoolkit/dojox/grid/resources/Grid.css";
        @import "js/dojotoolkit/dojox/grid/resources/pfgaGrid.css";
    </style>

    <script src="js/dojotoolkit/dojo/dojo.js" type="text/javascript" djConfig="parseOnLoad: true"></script>

    <script type="text/javascript">
        dojo.require("dojo.parser");
        dojo.require("dojox.grid.DataGrid");
        dojo.require("dojox.data.XmlStore");
        dojo.require("dijit.layout.ContentPane");
    </script>
</head>

<body class="pfga">

<div dojotype="dojox.data.XmlStore" url="events.xml" jsID="eventStore"></div>

<table dojoType="dojox.grid.DataGrid" store="eventStore" class="pfga" style="height:500px" clientSort="true" jsID="eventGrid">
  <thead>
    <tr>
      <th field="date" width="80px">Date</th>
      <th field="description" width="600">Description</th>
      <th field="DateID" sortDesc="true" hidden="false">DateSort</th>
    </tr>
    <tr>
        <th field="time" colspan="3">Details</th>
    </tr>
  </thead>
</table>

</body>
A: 

It looks like the Sort started to work once I added the JSID to solve my filtering problem

Morgan Delvanna
A: 

For the record, in dojo 1.5 it's the 'sortInfo' param passed to the Data Grid. It uses the same convention as the 'canSort' function, i.e. a number indicating the column (starting at 1) and the sign indicating the direction of sort.

I added a comment to http://docs.dojocampus.org/dojox/grid/DataGrid to this effect.

For example, this grid is sorted by the 'created' column in 'most recent first' order:

<table dojoType="dojox.grid.DataGrid" clientSort="true" selectionMode="single"
   formatterScope="formatterScope" dojoAttachPoint="logGrid" sortInfo="-2">
   <thead><tr>
    <th field="clientId" width="10%">Client ID</th>
    <th field="created" width="20%" formatter="datefmt">Created</th>
    <th field="message" width="30%" formatter="messagebodyfmt">Message</th>
    <th field="token" width="10%">Token</th>
    <th field="type" width="20%">Type</th>
    <th field="username" width="10%">Username</th>
   </tr>
</table>

Of course your choice of store and the way it understands the sort directives will have further impact, for example I'm using JsonQueryRestStore and the sortInfo param results in the store query including sort syntax based on dojox.data.JsonQuery and the backend handling the query must understand how to sort the data before returning it.

Nick Fenwick