views:

414

answers:

1

Hello I am using dojo.data.ItemFileWriteStore to draw a dojo datagrid (which works fine) and the grid shows properly. I was using client side sorting and that was also working fine. but now I need to change the sorting and do that server side. For this I am trying to use onHeaderCellClick event, using which I am able to run a javascript function.. something like

 gridInfo = {
            store: myJsonStore,
            structure: myStructure
            onHeaderCellClick:getSortedTable
         };

Now here is the getSortedTable function which I want to use to make another call to the server - passing the cell name, Table Name and the sort Order (asc or desc).

 function getSortedTable(e)
    {
  var cellName = e.cell.name;
            var tableName = ?
            var sortOrder = ?
          // getSortedTablefromServer(cellName, sortOrder, tablename)
    }

but the only thihng I am able to get out of from the 'e' parameter is the cell Name and may be the table Name.

  1. How can I get or keep a track of weather it will be ascending order required by the user or is it descending order.
  2. Also - how will I show the little arrow on the header of the column to show the user that the data is in descending or ascending?

Any help is highly appreciated!!

Thanks,

A: 

You will likely be better off modifying your data store to handle the server-side sorting rather than the grid (e.g. append the sort criteria as a query parameter to the XHR call triggered by fetch(), rather than sorting the result set client side). The grid should behave exactly as it does with client-side sorting, as it will just reflect the sort order of the data store.

From dojo.data.api.Read regarding fetch():

If a sort parameter is specified, this is a indication to the datastore to 
sort the items in some manner before returning the items.  The array is an array of 
javascript objects that must conform to the following format to be applied to the
fetching of items:
    {
        attribute: attribute || attribute-name-string,
        descending: true|false;   // Optional.  Default is false.
    }
Note that when comparing attributes, if an item contains no value for the attribute
(undefined), then it the default ascending sort logic should push it to the bottom 
of the list.  In the descending order case, it such items should appear at the top of the list.
Scott Christopher
I apologize for this late reply. I still need to get back to this issue. Was stuck up with some other stuff till now. I will try to implement the fetch and get back with what I found... Thanks for your reply!!
Zoom Pat