Hi,
I'm trying to implement a custom sort for my Grid. I'm using a dojox.grid.data.DojoData which I feed a store, faked out like this;
var store = new dojo.data.ItemFileReadStore({data: json});
In the test directory under dojo.grid there's an example using custom sorting, like this;
---
compare2ndLetter = function(inA, inB) {
// sort on the second letter
// return <0, 0, >0
console.log("compare custom called");
return inA.charCodeAt(1) - inB.charCodeAt(1);
}
// custom compare functions for sorting belong to the data model
// data model keeps this kind of metadata in a object called 'fields'
// you can install the custom compare function directly into fields
// model.fields.get(3).compare = compare2ndLetter;
// or you could setup fields when instantiating the model
model = new dojox.grid.data.Table([{}, {}, {}, {compare: compare2ndLetter}], data);
---
I have used both method described above, and made certain with console.dir that the compare method is indeed set, but it is never called when I sort a column. I think that the problem has to do with my using a DojoData object and the example uses a Table object.
Do I have to use a table, or could I possibly minimize changes to my code and use the DojoData object and yet get custom sorting?
Cheers,
PS

With some recent changes in
With some recent changes in the Grid, the sorting is done on the store, not the model. I suspect that is the root of the problem you see (me too).
I ended up doing something like this:
grid.model.store.comparatorMap = {}; grid.model.store.comparatorMap['active'] = sortText; ...where 'active' is a field name. 'sortText' is my function that does the sorting.
Using sort function by using DojoGrid!
Hi!
I have just researched DojoGrid for my project. But I have not enough time to understand all of them. I want to write a fuction sort_table(field_name), and DataGrid will auto call this function when the page was loaded.
Please help me!!!
Thanks very much!!
Hmm. I can't get the sorting to work
I'm using the following;
var grid = new dojox.Grid(
{
structure: layout,
model: model,
headerStyles: this.headerStyles
}, gridnode);
grid.model.store.comparatorMap = {};
for (var i in numbercols)
{
var colname = numbercols[i];
console.log("Setting number sorting function fo column '"+colname+"'");
grid.model.store.comparatorMap[colname] = sortNumber;
}
And I get the output
Setting number sorting function fo column 'Impressions'
Setting number sorting function fo column 'Clicks'
Which are the correct names of the columns, even so, my sorting function never gets called.
I'm using 1.1b1. Does the example use another version?
Cheers
PS
Not sure what "colname" is,
Not sure what "colname" is, but the value used in the comparator needs to be the model and store "field" name, not a name of one of the columns.
Works for pre-1.1b1 and post-1.1b1.
Remember, you are sorting the "store", so use store field names. Once the store is sorted, it will refresh the grid, reflecting the sorted store and the currently active query.
My humble apologies
I had a head-smacker here the other day. I was using all-lowercase for filed names and uppercase for name names :) in the grid format. For some reason my subconscious decided that it would be a great idea to use 'name' instead of 'field' to look up the field to add a customer handler to .
When I used the field name instead, everything works smooth, of course.
Congrats to the 1.1 release!
Cheers,
PS