Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New Sales Order - Item List Does Not Sort - SOLVED
11-17-2017, 02:29 AM,
#2
RE: New Sales Order - Item List Does Not Sort
Hi Paul, I did fix up this table sorting code a couple of years back, and set the code to Rafael. I don't think he ever had time to apply it though as it needed changes to all tables that require sorting. Basically all the header rows of a table that requires sorting need to be inside <thead></thead> tags, then the actual data that requires sorting (and nothing else) needs to be inside <tbody></tbody> tags and then any lines that appear at the bottom of the table and after the data need to be within <tfoot></tfoot> tags.

Then the SortSelect() function in javascripts/MiscFunctions.js needs to be replaced with the following:


function SortSelect() {
selElem = this;
var e = new Array;
th = localStorage.Theme;
columnText = selElem.innerHTML;
TableHeader = selElem.parentNode;
TableBodyElements = TableHeader.parentNode.parentNode.getElementsByTagName('tbody');
table = TableBodyElements[0];
i = TableHeader;
for (var t = 0, n; n = i.cells[t]; t++) {
if (i.cells[t].innerHTML == columnText) {
columnNumber = t;
s = getComputedStyle(i.cells[t], null);
if (s.cursor == "s-resize") {
i.cells[t].style.cursor = "n-resize";
i.cells[t].style.backgroundImage = "url('css/" + th + "/images/descending.png')";
i.cells[t].style.backgroundPosition = "right center";
i.cells[t].style.backgroundRepeat = "no-repeat";
i.cells[t].style.backgroundSize = "12px";
direction = "a"
} else {
i.cells[t].style.cursor = "s-resize";
i.cells[t].style.backgroundImage = "url('css/" + th + "/images/ascending.png')";
i.cells[t].style.backgroundPosition = "right center";
i.cells[t].style.backgroundRepeat = "no-repeat";
i.cells[t].style.backgroundSize = "12px";
direction = "d"
}
}
}
for (var r = 0, i; i = table.rows[r]; r++) {
var o = new Array;
for (var t = 0, n; n = i.cells[t]; t++) {
if (i.cells[t].tagName == "TD") {
o[t] = i.cells[t].innerHTML;
columnClass = i.cells[columnNumber].className
}
}
e[r] = o
}
e.sort(function (e, t) {
if (direction == "a") {
if (columnClass == "number") {
return parseFloat(e[columnNumber].replace(/[,.]/g, '')) - parseFloat(t[columnNumber].replace(/[,.]/g, ''))
} else if (columnClass == "date") {
if (e[columnNumber] !== undefined) {
da = new Date(convertDate(e[columnNumber], localStorage.DateFormat));
} else {
da = new Date(e[columnNumber]);
}
db = new Date(convertDate(t[columnNumber], localStorage.DateFormat));
return da > db
} else {
return e[columnNumber].localeCompare(t[columnNumber])
}
} else {
if (columnClass == "number") {
return parseFloat(t[columnNumber].replace(/[,.]/g, '')) - parseFloat(e[columnNumber].replace(/[,.]/g, ''))
} else if (columnClass == "date") {
if (e[columnNumber] !== undefined) {
da = new Date(convertDate(e[columnNumber], localStorage.DateFormat));
} else {
da = new Date(e[columnNumber]);
}
db = new Date(convertDate(t[columnNumber], localStorage.DateFormat));
return da <= db
} else {
return t[columnNumber].localeCompare(e[columnNumber])
}
}
});
for (var r = 0, i; i = table.rows[r]; r++) {
var o = new Array;
o = e[r];
for (var t = 0, n; n = i.cells[t]; t++) {
if (i.cells[t].tagName == "TD") {
i.cells[t].innerHTML = o[t]
}
}
}
return
}

This function now sorts dates correctly as well as alpha numeric. It only took me a couple of hours to get all the tables changed in my code, it just requires a developer to actually do it.

Thanks
Tim
Reply


Messages In This Thread
RE: New Sales Order - Item List Does Not Sort - by TimSchofield - 11-17-2017, 02:29 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)