11-16-2017, 11:53 PM,
(This post was last modified: 11-19-2017, 11:40 PM by VortecCPI.)
|
|
VortecCPI
Paul Becker
|
Posts: 751
Threads: 211
Joined: Apr 2017
|
|
New Sales Order - Item List Does Not Sort - SOLVED
Table Header sort click functionality does not work for Item data in list when creating a new Sales order. This can be addressed using methods discussed in this thread: http://www.weberp.org/forum/showthread.p...ht=sorting
I addressed the issue by inserting "echo '</table><table>';" at lines 1680 and 1773 but I think somebody should have a look at the code to be sure any fix adheres to webERP best practices.
https://www.linkedin.com/in/eclipsepaulbecker
|
|
11-17-2017, 02:29 AM,
|
|
TimSchofield
Tim Schofield
|
Posts: 1,318
Threads: 22
Joined: Mar 2015
|
|
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
|
|
11-17-2017, 03:18 AM,
|
|
VortecCPI
Paul Becker
|
Posts: 751
Threads: 211
Joined: Apr 2017
|
|
RE: New Sales Order - Item List Does Not Sort
Tim,
As usual thank you for your quick response and thorough explanation!
Paul
https://www.linkedin.com/in/eclipsepaulbecker
|
|
11-17-2017, 03:34 AM,
|
|
TimSchofield
Tim Schofield
|
Posts: 1,318
Threads: 22
Joined: Mar 2015
|
|
RE: New Sales Order - Item List Does Not Sort
Thanks Paul.
I forgot to mention I also moved the default date format and the theme name to the browser local storage, so I needed to add the following code to includes/header.php (the SortSelect() function uses them):
echo '<script>
localStorage.setItem("DateFormat", "', $_SESSION['DefaultDateFormat'], '");
localStorage.setItem("Theme", "', $_SESSION['Theme'], '");
</script>';
Tim
|
|
11-17-2017, 08:21 AM,
|
|
VortecCPI
Paul Becker
|
Posts: 751
Threads: 211
Joined: Apr 2017
|
|
RE: New Sales Order - Item List Does Not Sort
UPDATE...
I simply added:
+ At line 1701: echo '<tbody>';
+ At line 1794: echo '</tbody>';
Now sorting works as expected and table layout looks fine.
Thank you again for your hep!
https://www.linkedin.com/in/eclipsepaulbecker
|
|
11-18-2017, 01:04 AM,
|
|
VortecCPI
Paul Becker
|
Posts: 751
Threads: 211
Joined: Apr 2017
|
|
RE: New Sales Order - Item List Does Not Sort
UPDATE...
I also added the following to PO_Items.php:
+ At line 1192: echo '<tbody>';
+ At line 1262: echo '</tbody>';
Now sorting works as expected and table layout looks fine.
https://www.linkedin.com/in/eclipsepaulbecker
|
|
02-17-2018, 02:45 PM,
(This post was last modified: 02-18-2018, 10:15 AM by TurboPT.)
|
|
TurboPT
Administrator
|
Posts: 727
Threads: 10
Joined: Jun 2012
|
|
RE: New Sales Order - Item List Does Not Sort - SOLVED
Ok Tim,
If I have the full scope of the sorting needs, this appears to be the necessary changes:
- The localStorage portion (to the header)
- Replace the existing SortSelect with your SortSelect update
- Then for the sortable tables:
- Add <thead> wrap around the <th> columns that have sorting
- Add <tbody> tags for the sorted rows (after <thead>)
- Add <tfoot> -- only appears necessary if a 'totals' row, or some other summary row(s) to avoid being sorted?
That will be my general plan at the moment, unless other aspects are missing.
Also, if the three "problem" SVN files need these changes, then changes to only those three files will be delayed, though I will apply the changes locally to have them ready to commit -- if we can ever get those corrected.
|
|
|