WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 Sortable table not working properly, Andrus Moor, July 19, 2003
     Re:Sortable table not working properly, Erik Arvidsson, July 20, 2003

Subject: Re:Sortable table not working properly From: Erik Arvidsson Date: July 20, 2003
The problem is not in SortableTable. The problem is in your code.

getRowValue does not take the text inputs into account.

Then you have forgotten to use your custom sort. You need to pass along the sort types to the constructor.

erik

________________________________________________________


To reproduce
1. Run the following code in IE
2. Click in one of the columns to sort.
Observed result: table is not sorted
Expected result: tabel must be sorted by that column.
Any idea how to use sortable table with multiple <input type=text>,
<input type=checkbox> and <select> columns ?

Code to reproduce:
<table id=result>
<thead><tr><td>Col1</td><td>Col2<td></tr></thead>
<tr><td><input type=checkbox checked></td><td><input type=text value=c></td></tr>
<tr><td><input type=checkbox ></td><td><input type=text value=a></td></tr>
<tr><td><input type=checkbox checked></td><td><input type=text value=b></td></tr>
</table>

<script type="text/javascript" src="http://webfx.eae.net/dhtml/sortabletable/js/sortabletable.js"></script>
<script>
SortableTable.prototype._getRowValue = SortableTable.prototype.getRowValue;
SortableTable.prototype.getRowValue = function (oRow, sType, nColumn) {
if (sType == "CheckBox") {
return oRow.cells[nColumn].firstChild.checked ? 1 : 0;
}
return this._getRowValue(oRow, sType, nColumn);
};

if (/MSIE/.test(navigator.userAgent)) {
SortableTable.prototype.onbeforesort = function () {
var table = st.element;
var inputs = table.getElementsByTagName("INPUT");
var l = inputs.length;
for (var i = 0; i < l; i++) {
inputs[i].parentNode.parentNode.setAttribute('_c'+inputs[i].uniqueID,inputs[i].checked);
inputs[i].parentNode.parentNode.setAttribute('_v'+inputs[i].uniqueID,inputs[i].value);
}
};

// restore check box values
SortableTable.prototype.onsort = function () {
var table = st.element;
var inputs = table.getElementsByTagName("INPUT");
var l = inputs.length;
for (var i = 0; i < l; i++) {
inputs[i].checked = inputs[i].parentNode.parentNode.getAttribute('_c'+inputs[i].uniqueID);
inputs[i].value = inputs[i].parentNode.parentNode.getAttribute('_v'+inputs[i].uniqueID);
}
};
}
var st=new SortableTable(document.getElementById("result"));
</script>



Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX