Contribution: drag drop column reordering
I managed to get reordering of columns using drag drop working for my app and thought the code might be useful to others too.
The solution uses the Prototype and Scriptaculous libraries (http://script.aculo.us/)
Please modify the paths in the head section appropriately when you copy the code.
There is a slight difference in the code for ActiveWidgets 2.0.2 and 2.5 beta 1 (just the element used in Sortable.create)
Both versions are included below.
Drag the column headers to rearrange the columns.
Library versions used:
======================
ActiveWidgets: 2.0.2 or 2.5 beta 1
Prototype: 1.6.0
Scriptaculous: 1.8.0
Here's the code for AW 2.0.2:
<html>
<head>
<script src="activewidgets 2.0.2/runtime/lib/aw.js"></script>
<link href="activewidgets 2.0.2/runtime/styles/xp/aw.css" rel="stylesheet"></link>
<script src="scriptaculous/lib/prototype.js"></script>
<script src="scriptaculous/src/scriptaculous.js"></script>
</head>
<body>
<script>
function changeColumnOrder() {
var j = 0;
var columnIndicesOrder = [];
for(i=0; i < document.getElementById('myGrid-headers-0-1').childNodes.length; i++) {
var headerId = document.getElementById('myGrid-headers-0-1').childNodes[i].id;
if ((headerId.match("myGrid-header") != null) && (headerId.match("myGrid-headers") == null)) {
var temp = headerId.split("-");
columnIndicesOrder[j++] = temp[2];
}
}
obj.setColumnIndices(columnIndicesOrder);
obj.refresh();
Sortable.create('myGrid-headers-0-1',{tag:'span',only:'aw-grid-header',constraint:'false',overlap:'vertical',onUpdate:changeColumnOrder,scroll:'myGrid-scroll-box'});
headerId = null;
}
var obj = new AW.Grid.Extended;
obj.setId("myGrid");
obj.setFixedLeft(0);
obj.setCellText(function(i, j){return i + " " + j});
obj.setHeaderText(["0", "1", "2", "3", "4", "5", "6", "7"], 0);
obj.setColumnCount(8);
obj.setRowCount(10);
document.write(obj);
Sortable.SERIALIZE_RULE = /^(.*)$/;
Position.includeScrollOffsets = true;
Sortable.create('myGrid-headers-0-1',{tag:'span',only:'aw-grid-header',constraint:'false',overlap:'vertical',onUpdate:changeColumnOrder,scroll:'myGrid-scroll-box'});
</script>
</body>
</html>
And here's the code for AW 2.5 beta 1:
<html>
<head>
<script src="activewidgets 2.5b1/runtime/lib/aw.js"></script>
<link href="activewidgets 2.5b1/runtime/styles/xp/aw.css" rel="stylesheet"></link>
<script src="scriptaculous/lib/prototype.js"></script>
<script src="scriptaculous/src/scriptaculous.js"></script>
</head>
<body>
<script>
function changeColumnOrder() {
var j = 0;
var columnIndicesOrder = [];
for(i=0; i < document.getElementById('myGrid-headers-0-center').childNodes.length; i++) {
var headerId = document.getElementById('myGrid-headers-0-center').childNodes[i].id;
if ((headerId.match("myGrid-header") != null) && (headerId.match("myGrid-headers") == null)) {
var temp = headerId.split("-");
columnIndicesOrder[j++] = temp[2];
}
}
obj.setColumnIndices(columnIndicesOrder);
obj.refresh();
Sortable.create('myGrid-headers-0-center',{tag:'span',only:'aw-grid-header',constraint:'false',overlap:'vertical',onUpdate:changeColumnOrder,scroll:'myGrid-scroll-box'});
headerId = null;
}
var obj = new AW.Grid.Extended;
obj.setId("myGrid");
obj.setFixedLeft(0);
obj.setCellText(function(i, j){return i + " " + j});
obj.setHeaderText(["0", "1", "2", "3", "4", "5", "6", "7"], 0);
obj.setColumnCount(8);
obj.setRowCount(10);
document.write(obj);
Sortable.SERIALIZE_RULE = /^(.*)$/;
Position.includeScrollOffsets = true;
Sortable.create('myGrid-headers-0-center',{tag:'span',only:'aw-grid-header',constraint:'false',overlap:'vertical',onUpdate:changeColumnOrder,scroll:'myGrid-scroll-box'});
</script>
</body>
</html>
Suggestions, comments and bugs are welcome.
Ankur Motreja
November 15,