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
November 16,
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)
November 16,
I would be happy to look into adding alphabetical sorting capability. Where in your code is sorting taking place at this point?
November 16,
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)
November 17,
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
November 17,
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
November 17,
> Are you a Java programmer as well?
No, I only play with JavaScript ;-)
Alex (ActiveWidgets)
November 17,
I am having a problem sorting percentages. As soon as I add a percent sign they get sorted out of order.
Alex Kane
November 17,
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
May 19,
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
July 15,
The following code works like butter. Sorting leaves row-values to some temporary state which is not valid after the row count has changed...
...
var rowValues = [];
for(var i=0; i < myData.length; ++i) { rowValues[i] = i; }
obj.setRowProperty("values", rowValues);
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
July 21,
var newCount = obj.getDataProperty("count");
var rowValues = [];
for(var i=0; i < newCount; ++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
July 21,
...
obj.setDataProperty("count", myData.length);
var newCount = obj.getDataProperty("count");
var rowValues = [];
for(var i=0; i < newCount; ++i) { rowValues[i] = i; }
obj.setRowProperty("values", rowValues);
obj.setSortProperty("index", null);
obj.refresh();
Sudhaker Raj
July 23,
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();
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=0; i < newCount; ++i) { rowValues[i] = i; }
obj.setRowProperty("values", rowValues);
obj.setSortProperty("index", null);
obj.refresh();
Sudhaker Raj
July 26,
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
April 19,
Hi i would like to view some templates code description. can u help me? tnx!
Jen
jen
May 4,