:: Forum >> Version 1 >>

Upgrading from 1.0 to 1.0.1 broke sorting?

My code works fine with 1.0, but when I use 1.0.1, clicking on the column header no longer sorts the grid data. The status bar briefly flashes "sorting...", but nothing changes in the table. Does anyone else have a similar problem? Is there something new we need to set to make sorting work? I diff'ed the examples, and didn't see any changes. Here is a snippet of my code:

<script>
var locations = new Array(); // Array of oLocation
function oLocation(locationId, location) {
this.locationId = locationId;
this.location = location;
}
var locationsColumns = [
"<bean:message bundle="resmgmt" key="location.label"/>"
];
// oLocation(locationId, location)
<c:forEach items="${resourceForm.allLocations}" var="l_location">
locations[locations.length] = new oLocation(
'<c:out value="${l_location.locationId}"/>',
'<c:out value="${l_location.locationName}"/>'
);
</c:forEach>

var oLocationsGrid = new Active.Controls.Grid;
oLocationsGrid.setId("LocationsGrid");
oLocationsGrid.setRowProperty("count", locations.length);
oLocationsGrid.setColumnProperty("count", 1);
oLocationsGrid.setDataProperty("text", function(i, j){
switch (j) {
case 0:
return locations[i].location;
}
});
oLocationsGrid.setColumnProperty("text", function(i){return locationsColumns[i]});
// Add a doubleclick listener
var row = new Active.Templates.Row;
row.setEvent("ondblclick", function(){this.action("myAction")});
oLocationsGrid.setTemplate("row", row);
oLocationsGrid.setAction("myAction", function(src){doEditLocation()});
document.write(oLocationsGrid);
</script>

Any suggestions would be greatly appreciated. Thanks!
JohnG
Monday, June 27, 2005
John,

the sorting algorithm changed between 1.0 and 1.0.1 - the new one is 'stable' sorting which retains relative positions of items with equal values. I cannot say from your code why it breaks, maybe it has something to do with the values themselves. Could you send me the complete example so I can reproduce the problem?
Alex (ActiveWidgets)
Monday, June 27, 2005
My problem itself as either a table that would not sort at all, or a table that would sort only by the first column, regardless of what column header was clicked. It turns out that the library version was irrelevant, but the additional columns recently added to my table was the triggering change.

I saw another post here about someone having trouble with his switch statement not working, and that gave me someplace to start looking. Stepping through your source code, I noticed that sometimes it passes integers or strings(!) into my overloaded setDataProperty("text", function(i, j){}) function. As you see, I am using a switch statement and neglected to include a default case. If I had a default case, I would have figured this out a lot faster. So as a work-around, I modified my code to look like:

oLocationsGrid.setDataProperty("text", function(i, j){
// Look out for string or integer parameters!
if(j==0 || j=="0") {
return locations[i].location;
} else {
window.alert("Cannot find column "+j);
}
});

I didn't try to find the source of the string parameters, but I hope I've given you some clues where to go look. Thanks!
JohnG
Thursday, September 29, 2005



This topic is archived.

Back to support forum

Forum search