diff --git a/sortt.js b/sortt.js index 75a4f0e..511cd4c 100644 --- a/sortt.js +++ b/sortt.js @@ -44,6 +44,41 @@ window.sortt=function(normsort,revsort,isdefault){ window.location.replace(url.href); }; +//create global function with main routine +function getArrow(normsort,revsort,isdefault){ + //sortt [normsort] (revsort) (isdefault) + + //arrows + var arrow_down = '⯆'; // U+2BC6 + var arrow_up = '⯅'; // U+2BC5 + + //normsort is needed + if (!(normsort)) return false; + + //default values of optinal parameters + if (!(revsort)) revsort = ""; + + //get sort param from url + let url_sort = (new URL(window.location)).searchParams.get("sort"); + + if ((url_sort === null) && isdefault) { + //if sort is sorted as default add arrow tho this table header + if (isdefault) return arrow_down; + } else { + //if sort arg is in url test if it corelates with colum header sort arguments + if (url_sort === normsort) { + //the table is sorted with this header normal + return arrow_down; + } else if (url_sort === revsort) { + //the table is sorted with this header reverse + return arrow_up; + } else { + //the table is NOT sorted with this header + return false; + } + } +} + //USE Functions