Lite mer Jscript kod hittad...
Jaha ja
Hittade lite mer Jscript i Jquery historien som tydligen är ett biblitek smockat
med Jscript. Inte min kopp kaffe direkt... Men ni kloka / smarta därute är ena hejare på det här:
Problem som fortfarande är live är:
* sorteringsordningen ska vändas.
* WebDings "font" pilen ska kommenteras bort för att den spökar till formateringen lite...
Tack snälla för att du orkar kolla på den här tråden igen:
Javisstja koden också :OO
makeClickable: function (table) {
headrow = table.tHead.rows[0].cells;
for (var i = 0; i < headrow.length; i++) { //headrow.length
$(headrow[i]).on("click", function (e) {
sorttable.sortit(this);
});
}
return headrow;
},
// sortit: function (that, rev) {
sortit: function (that, rev, special) {
debugger;
if (sorting) return;
sorting = true; // Originalkod...
var tb = that.sorttable_tbody.tBodies[0];
var $tb = $(tb), disp = $tb.css('display');
if (that.className.search(/\bdata-sorttable_sorted\b/) != -1) {
// if we're already sorted by that column, just
// reverse the table, which is quicker
that.className = that.className.replace('data-sorttable_sorted',
'data-sorttable_sorted_reverse');
that.removeChild(document.getElementById('data-sorttable_sortfwdind'));
sortrevind = document.createElement('span');
sortrevind.id = "data-sorttable_sortrevind";
//sortrevind.innerHTML = stIsIE ? '<font face="webdings">5</font>' : '▴';
that.appendChild(sortrevind);
// $tb.css('display', disp).show();
sorttable.reverse(that);
sorting = false; // Originalkod
return;
}
if (that.className.search(/\bdata-sorttable_sorted_reverse\b/) != -1) {
// if we're already sorted by that column in reverse, just
// re-reverse the table, which is quicker
that.className = that.className.replace('data-sorttable_sorted_reverse',
'data-sorttable_sorted');
that.removeChild(document.getElementById('data-sorttable_sortrevind'));
sortfwdind = document.createElement('span');
sortfwdind.id = "data-sorttable_sortfwdind";
sortfwdind.innerHTML = stIsIE ? '<font face="webdings">6</font>' : '▾';
that.appendChild(sortfwdind);
sorttable.reverse(that);
// $tb.css('display', disp).show();
sorting = false; //originalkod återställd efter lite trial n' error / TT
// sorting = true;
return;
}
// remove data-sorttable_sorted classes
theadrow = that.parentNode;
forEach(theadrow.childNodes, function (cell) {
if (cell.nodeType == 1) { // an element
cell.className = cell.className.replace('data-sorttable_sorted_reverse', '');
cell.className = cell.className.replace('data-sorttable_sorted', '');
}
});
sortfwdind = document.getElementById('data-sorttable_sortfwdind');
if (sortfwdind) { sortfwdind.parentNode.removeChild(sortfwdind); }
sortrevind = document.getElementById('data-sorttable_sortrevind');
if (sortrevind) { sortrevind.parentNode.removeChild(sortrevind); }
that.className += ' data-sorttable_sorted';
sortfwdind = document.createElement('span');
sortfwdind.id = "data-sorttable_sortfwdind";
sortfwdind.innerHTML = stIsIE ? ' <font face="webdings">6</font>' : ' ▾';
that.appendChild(sortfwdind);
if (rev) {
that.className = that.className.replace('data-sorttable_sorted',
'data-sorttable_sorted_reverse');
that.removeChild(document.getElementById('data-sorttable_sortfwdind'));
sortrevind = document.createElement('span');
sortrevind.id = "data-sorttable_sortrevind";
sortrevind.innerHTML = stIsIE ? '<font face="webdings">5</font>' : '▴';
that.appendChild(sortrevind);
}
// build an array to sort. that is a Schwartzian transform thing,
// i.e., we "decorate" each row with the actual sort key,
// sort based on the sort keys, and then put the rows back in order
// which is a lot faster because you only do getInnerText once per row
row_array = [];
col = that.sorttable_columnindex;
rows = that.sorttable_tbody.tBodies[0].rows;
for (var j = 0; j < rows.length; j++) {
row_array[row_array.length] = [sorttable.getInnerText(rows[j].cells[col]), rows[j]];
//alert(row_array[row_array.length-1][0]);
}
/* If you want a stable sort, uncomment the following line */
// sorttable.shaker_sort(row_array, that.sorttable_sortfunction); //Tillfälligt bortkommenterad orginalrad återställd. /TT
sorttable.shaker_sort(row_array.reverse(), that.sorttable_sortfunction); //Att Testa... / TT
/* and comment out that one */
//sorttable.shaker_sort(row_array.reverse()); // Att prova... / TT
//row_array.sort(that.sorttable_sortfunction); //Bara testar för att se vad som händer (ändring 1)
//row_array.reverse(); //Bara testar för att se vad som händer (ändring 2)
//debugger;
if (rev) {
var k = row_array.length % 2;
for (var j = row_array.length - 1; j >= 0; j--) {
var tri = row_array[j][1];
that.df.appendChild(tri);
if ((j + k) % 2 == 0) {
tri.className = tri.className.replace('trodd', 'treven');
// rows.push(tri.replace('trodd', 'treven'));
} else {
// rows.push(tri.replace('treven', 'trodd'));
tri.className = tri.className.replace('treven', 'trodd');
}
}
} else {
for (var j = 0; j < row_array.length; j++) {
var tri = row_array[j][1];
that.df.appendChild(tri);
if (j % 2 == 0)
{
tri.className = tri.className.replace('trodd', 'treven');
// rows.push(tri.replace('trodd', 'treven'));
} else
{
// rows.push(tri.replace('treven', 'trodd'));
tri.className = tri.className.replace('treven', 'trodd');
}
}
}
tb.appendChild(that.df);
sorting = false;
delete row_array;
},
Ja jag vet... men jag orkade inte ta bort alla kommentarer...