3.2.0

Bad Sorting

Hey,
I was having a problem sorting. Despite setting up my test exactly like one of the examples whenever I tried to sort by clicking on a column the control would sort only by the row number.
After rooting around in the code I found the source(?) of the problem... The index in the sortColumn method was a string instead of an integer. So I put parseInt around it and it seemed to fix the problem.
But here's what's weird, the examples on this page don't have that problem! So I figured you were using a different version of the script and I changed my source temporarily to your copy - and it still didn't work.
So the question is, why does your example work and mine not? The only difference I can see is the data array although it loads the data OK. I even tried making a copy of your example and directing it to my copy of the code - and it worked!

I know I'm missing something incredibly obvious but I can't see it for the life of me!!!

<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">

<head>
<base href="http://cbb/">
<title>Search Results List</title>
<link href="Grid/styles/xp/grid.css" rel="stylesheet" type="text/css">
<style>
  body {
    overflow: hidden;
  }
  .active-controls-grid {
    position: absolute;
    top: 0px;
    left: 0px;
    height: 100%;
    width: expression(this.parentNode.offsetWidth-3);
    font: menu;
  }
</style>
<script src="grid/lib/grid.js"></script>
<!--script src="http://www.activewidgets.com/runtime/lib/grid.js"></script-->
<script>
var myData = [ ["dbID", "pgID",     "Gender", "Age",  "Height (cm)", "Weight (Kg)", "Status"],
             ["0",    "Test 0",   "FEMALE", "0",    "70",  "100",  "PRE-SCREENED"],
             ["1",    "Test 1",   "MALE",   "1",    "72",  "101",  "SCREENED"],
             ["2",    "Test 2",   "MALE",   "2",    "73",  "102",  "SCREENED"],
             ["3",    "Test 3",   "FEMALE", "3",    "74",  "103",  "PRE-SCREENED"],
             ["4",    "Test 4",   "FEMALE", "4",    "75",  "104",  "SCREENED"],
             ["5",    "Test 5",   "MALE",   "5",    "76",  "105",  "SCREENED"],
             ["6",    "Test 6",   "MALE",   "6",    "77",  "106",  "PRE-SCREENED"],
             ["7",    "Test 7",   "MALE",   "7",    "78",  "107",  "SCREENED"],
             ["8",    "Test 8",   "FEMALE", "8",    "78",  "108",  "SCREENED"],
             ["9",    "Test 9",   "MALE",   "9",    "80",  "109",  "PRE-SCREENED"],
             ["10",   "Test 10",  "MALE",   "37",   "78",  "77",  "SCREENED"] ];
</script>
</head>

<body>
<div id="box" style="height:100%;width:100%;">
</div>
  <script>
    var results = new Active.Controls.Grid;

    results.setColumnProperty("count", myData[0].length-2);
    results.setColumnProperty("text", function(j){return myData[0][j+2];});
    results.setColumnHeaderHeight("20px");

    results.setRowProperty("count", myData.length-1);
    results.setRowProperty("text", function(i){return myData[i+1][1];});
    results.setRowHeaderWidth("200px");

    results.setDataProperty("text", function(i,j){return myData[i+1][j+2];});

    results.setAction("click", function(src){alert(src._id);alert(src.getItemProperty("text"))});
    document.getElementById("box").innerHTML = results;
  </script>
</body>
</html>
Dav
April 7,
Hi Dav.
Just for trying : remove the DOCTYPE and try again ?
SgtKabukinan
April 7,
No change. Does that effect how values are represented/passed? Those tags are all black boxes to me!
Dav
April 7,
Well, this looks like a serious problem in grid sorting code. For some reason sorting procedure sends row/column arguments as strings and display procedure send them as numbers, so your data binding functions work in one case and don't work in another. You can fix it with:

results.setDataProperty("text", function(i,j){return myData[Number(i)+1][Number(j)+2];});

I am not sure yet what to do with this problem - I never said that row/column indices should be numbers, in fact it could be any unique IDs.

---
Unrelated to sorting - grid CSS only works in quirks mode, but your DOCTYPE triggers standards-compliant mode, which is not supported.
Alex (ActiveWidgets)
April 7,
Eeeexxxxcellent!

Thanks for the speedy reply!!!
Dav
April 7,
I was REALLY confused for a while....
Alex (ActiveWidgets)
April 7,

This topic is archived.

See also:


Back to support forum