Sort on Row Header Field??
I have a grid implemented where I have added my own row Headers via the obj.setRowText. The issue I am stuck with right now is being able to sort on that row.
When the grid first loads, I have pre-sorted the arrays on the server so that the rowHeaders are in fact the initial sort (alpha asc). If a user clicks on any of the other columns in the grid there is however no way to resort the grid back to the initial state, i.e. resort the grid based on the rowHeaders.
So I am seeking help in understanding how I can sort based on the rowText.
Dean
May 6,
No-one has any ideas or help?
Dean
May 11,
Something like this:
function restoreInitialSort(){
var count = obj.getRowProperty("count");
var array = [];
for (i=0; i<count; i++){
array[i] = i;
}
obj.setRowProperty("values", array);
obj.setSortProperty("index", -1);
obj.refresh();
}
var corner = obj.getLayoutTemplate().getContent("corner");
corner.setEvent("onclick", restoreInitialSort);
This thread may also help a little bit:
http://www.activewidgets.com/messages/1038-3.htm
Alex (ActiveWidgets)
May 11,
Alex thanks for posting code above. This almost does it for me. I guess I did not explain myself well enough in the initial question. What I want to be able to do is be able to sort column 0 as you can any other column in the grid (1 to n). I can hook up the event handler as above, but are stuggling with how to enable sorting of column 0 both ascending/descending.
Thanks in advance
Dean
May 18,
Here is the code which does proper sorting:
var obj = new Active.Controls.Grid;
obj.setRowProperty("count", 20);
obj.setColumnProperty("count", 5);
obj.setDataProperty("text", function(i, j){return myData[i][j]});
obj.setColumnProperty("text", function(i){return myColumns[i]});
obj.setRowProperty("text", function(i){return this.getDataProperty("text", i, 0)});
obj.setColumnProperty("values", [1,2,3,4]);
obj.setRowHeaderWidth("100px");
obj.setColumnHeaderHeight("20px");
obj.defineTemplate("corner", new Active.Templates.Header);
obj.getLayoutTemplate().setContent("corner", function(){return this.getCornerTemplate(0)});
var corner = obj.getCornerTemplate();
corner.getItemProperty = function(name){return this.getColumnProperty(name, 0)};
corner.getContent("div").setEvent("onmousedown", null);
corner.getContent("div").setStyle("cursor", "default");
corner.setStyle("width", "100px");
corner.setStyle("height", "20px");
corner.setStyle("text-align", "center");
document.write(obj);
The example is based on JS array, but it should work with XML data models as well.
Alex (ActiveWidgets)
May 19,