:: Forum >> Version 1 >>

Sorting

Greetings:

1) You are in the process of creating something outstanding here. If you have the opportunity to enhance the documentation of the code, it would make it much easier for me to offer real assistance with improvements and bug fixes.

2) At the moment, I notice that sorts are done on an ASCII basis. I need case insentive alphabetical. Is there an option for this that already exists in the code? It so, what is the option. If not, is this something you could add, and/or let me know where in the code this is handled and I will take a pass at it.

Please advise.

Regards,

Tal
Sunday, November 16, 2003
The documentation is a top priority here. It does not come easy at all but I'm going to imrove it step by step.

As for the sorting - it is not possible to change the the default (ASCII) sorting in the current version. I was planning to rewrite the sorting block, adding the possibility to supply your own 'compare' function, so this should be possible in the near future.
Alex (ActiveWidgets)
Sunday, November 16, 2003
I would be happy to look into adding alphabetical sorting capability. Where in your code is sorting taking place at this point?
Sunday, November 16, 2003
Sorting is in the grid control class:
sourcelibcontrolsgrid.js
method 'sort' (end of the file)
the function retrieves the array of row indices:
rows = this.getRowProperty("values")
retrieves the column's data into temporary array:
a[i]= ... this.getDataProperty("text", i, index)
sorts the row indices array using custom 'compare' functions:
rows.sort(direction == "ascending" ? ascending : descending);
then stores back the row index array:
this.setRowProperty("values", rows)

Alex (ActiveWidgets)
Monday, November 17, 2003
Great. I was hunting around and found that very method. I will take a crack at implementing an alphabetical sort.

BTW: You have have done some outstanding work with this stuff. Are you a Java programmer as well?

Peace,

Tal
Monday, November 17, 2003
Alexander:

Here is the fix for the sorting bug...

Replace line 253 from grid.js

v1 = this.getDataProperty("text", i, index);

with

v1 = this.getDataProperty("text", i, index).toLowerCase();

The sort is now case insensitive and functions as expected.

Regards,

Tal
Monday, November 17, 2003
> Are you a Java programmer as well?

No, I only play with JavaScript ;-)
Alex (ActiveWidgets)
Monday, November 17, 2003
I am having a problem sorting percentages. As soon as I add a percent sign they get sorted out of order.
Alex Kane
Monday, November 17, 2003
I had to set not only:
obj.setDataProperty("text", function(i, j){return myData[i][j]});
but:
obj.setDataProperty("value", function(i, j){return myData [i][j]});
in order to get my data to sort correctly.
Did I do something wrong?
Keith
Wednesday, May 19, 2004
Yeah - this is suggested work around !!!

Perhaps It will be better if grid gives some API to clear the internally maintained 'value' array.

We call something like grid.reset(); and then pass new data array to setText and do a grid.refresh()...
Sudhaker Raj
Thursday, July 15, 2004

The following code works like butter. Sorting leaves row-values to some temporary state which is not valid after the row count has changed...

// add, remove in data array
...
// re-initialize the row values
var rowValues = [];
for(var 
i=0myData.length; ++i) { rowValues[i] = i; }
obj.setRowProperty("values"rowValues);
// re-initialize the data values
obj.setDataProperty("count"myData.length);
obj.refresh();
 
Sorry, if it's a duplicate post.

Alex, can we add the row-values re-initialization code inside setDataProperty method of grid? This way, changing row count will reset the row-values automatically and there will not be need of extra code.
Sudhaker Raj
Wednesday, July 21, 2004
// re-initialize the row values
var newCount obj.getDataProperty("count");
var 
rowValues = [];
for(var 
i=0newCount; ++i) { rowValues[i] = i; }
obj.setRowProperty("values"rowValues);
obj.setSortProperty("index"null);
 
Reset "sort/index" property too. Otherwise results are confusing and in-correct.
Sudhaker Raj
Wednesday, July 21, 2004
// add, remove in data array 
... 
// re-initialize the data values 
obj.setDataProperty("count"myData.length); 
// re-initialize the row values 
var newCount obj.getDataProperty("count"); 
var 
rowValues = []; 
for(var 
i=0newCount; ++i) { rowValues[i] = i; } 
obj.setRowProperty("values"rowValues); 
obj.setSortProperty("index"null); 
// ?? what about sorting direction ??
// refresh the grid
obj.refresh(); 
 
Sudhaker Raj
Friday, July 23, 2004
Working on something similar to yahoo quote example. Var newCount is 0 all the time. I know it is happening because data hasn't got fetched yet. Is there any work around?

var urlSearch "/myapp/Search.jsp?MyParam=" MyValue "&rand=" + (new Date()).getTime();
// alert(urlSearch);

var table = new Active.Text.Table;
table.setURL(urlSearch);
table.request();

obj.setDataModel(table);

var 
newCount obj.getDataProperty("count");
alert("newCount=" newCount);

var 
rowValues = [];
for(var 
i=0newCount; ++i) { rowValues[i] = i; }
obj.setRowProperty("values"rowValues);
obj.setSortProperty("index"null);

obj.refresh();
 
Sudhaker Raj
Monday, July 26, 2004
Bump...
Tuesday, August 3, 2004

This issue is resolved. Alex suggested a patch ;-) and working fine now.

Check this - http://thej2ee.com/x2/modules/newbb/viewtopic.php?topic_id=1&forum=4&post_id=1#forumpost1
Sudhaker Raj
Tuesday, August 17, 2004
I faced the invalid row counts while adding or deleting rows into/from the grid. but after the Sudhaker's example it helped me a lot to solve the issue.


thanks Sudhaker.


Kumar S
www.GuyFromChennai.com
Kumar S
Tuesday, April 19, 2005
Hi i would like to view some templates code description. can u help me? tnx!

Jen
jen
Wednesday, May 4, 2005



This topic is archived.

Back to support forum

Forum search