External sort model?
I'd like to define a custom sort function for certain columns. Is that possible? Is that what the external sort model is for?
Kevin
August 25,
<html>
<head>
<title></title>
<style>body {font: 12px Tahoma}</style>
<script src="../../runtime/lib/aw.js"></script>
<link href="../../runtime/styles/xp/aw.css" rel="stylesheet"></link>
<style>
#myGrid .aw-column-0 {width: 100px;}
#myGrid .aw-column-1 {width: 150px}
</style>
</head>
<body>
<span id="myGrid"></span>
<script>
var myData = [
["1", "1", "zd"],
["12", "12", "yyy"],
["23", "23", "ggggg"],
["100", "100", "555t"]
];
// custom sort to compare string lengths
StringLengthSort = AW.Formats.String.subclass();
StringLengthSort.create = function() {
var obj = this.prototype;
obj.comparator = function(values, greater, less, equal, error){
return function(i, j){
var v1 = values[i];
if (v1 == null) {
v1 = "";
}
var v2 = values[j];
if (v2 == null) {
v2 = "";
}
if (v1.length > v2.length) {
return greater * -1;
}
else if (v1.length < v2.length) {
return greater * 1;
}
return 0;
}
};
}
var myHeaders = ["string", "number", "string length"];
var grid = new AW.UI.Grid;
grid.setId("myGrid");
grid.setHeaderText(myHeaders);
grid.setCellData(myData);
grid.setCellFormat(new AW.Formats.Number, 1);
grid.setCellFormat(new StringLengthSort, 2);
grid.setColumnCount(3);
grid.setRowCount(4);
grid.refresh();
</script>
</body>
</html>
This topic is archived.
ActiveWidgets is a javascript library for creating user interfaces. It offers excellent performance for complex screens while staying simple, compact and easy to learn. Deployed by thousands of commercial customers in more than 70 countries worldwide.
Copyright © ActiveWidgets 2021