Skip to content

Commit

Permalink
Table sorting and filtering
Browse files Browse the repository at this point in the history
Table sorting updates
Table filtering
  • Loading branch information
Relkci authored Oct 27, 2023
1 parent 5dcc770 commit f6ef533
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions template/head.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

<script type="text/javascript"> /* table-sort-js Author: Lee Wannacott Licence: MIT License Copyright (c) 2021 Lee Wannacott GitHub Repository: https://github.com/LeeWannacott/table-sort-js */ function tableSortJs(e=!1,t=document){const[i]=function(){if(!0===e){return[t.getElementsByTagName("table")]}return[document.getElementsByTagName("table")]}(),n={},r={};for(let e of i)o(e);function o(i){let n,r;0===i.getElementsByTagName("thead").length?(n=!0===e?t.createElement("thead"):document.createElement("thead"),n.appendChild(i.rows[0]),i.insertBefore(n,i.firstChild),r=i.querySelectorAll("tbody").length>1?i.querySelectorAll("tbody")[1]:i.querySelector("tbody")):r=i.querySelector("tbody");const o=i.querySelector("thead").querySelectorAll("th");for(let[e,t]of o.entries())t.classList.contains("disable-sort")||(t.style.cursor="pointer",s(t,e,r,i))}function s(e,t,i,o){let s=e.classList.contains("order-by-desc"),l=o.classList.contains("table-arrows");const a=" ▲",c=" ▼";s?e.insertAdjacentText("beforeend",c):e.insertAdjacentText("beforeend",a);let b=0,u=[];e.addEventListener("click",(function(){const y=[],d=Array.prototype.filter.call(i.querySelectorAll("tr"),(e=>"none"!==e.style.display));let m=e.classList.contains("data-sort");m&&function(e,i){for(let[r,o]of e.entries()){const e=o.querySelectorAll("td").item(t).dataset.sort;i.push(`${e}#${r}`),n[i[r]]=o.innerHTML}}(d,y);let f=e.classList.contains("file-size");f&&function(e,i){const n=/[.0-9]+(\s?B|\s?KB|\s?KiB|\s?MB|\s?MiB|\s?GB|\s?GiB|T\s?B|\s?TiB)/i,r=/(\s?B|\s?KB|\s?KiB|\s?MB|\s?MiB|\s?GB|G\s?iB|\s?TB|\s?TiB)/i,o={Kibibyte:1024,Mebibyte:1049e3,Gibibyte:1074e6,Tebibyte:11e11,Pebibyte:1126e12,Kilobyte:1e3,Megabyte:1e6,Gigabyte:1e9,Terabyte:1e12};function s(e,t){return(e=e.replace(r,"")).replace(e,e*o[t])}for(let[o,l]of e.entries()){let e=l.querySelectorAll("td").item(t).textContent;e.match(n)?e.match(/\s?KB/i)?(e=s(e,"Kilobyte"),i.push(`${e}#${o}`)):e.match(/\s?KiB/i)?(e=s(e,"Kibibyte"),i.push(`${e}#${o}`)):e.match(/\s?MB/i)?(e=s(e,"Megabyte"),i.push(`${e}#${o}`)):e.match(/\s?MiB/i)?(e=s(e,"Mebibyte"),i.push(`${e}#${o}`)):e.match(/\s?GB/i)?(e=s(e,"Gigabyte"),i.push(`${e}#${o}`)):e.match(/\s?GiB/i)?(e=s(e,"Gibibyte"),i.push(`${e}#${o}`)):e.match(/\s?TB/i)?(e=s(e,"Terabyte"),i.push(`${e}#${o}`)):e.match(/\s?TiB/i)?(e=s(e,"Tebibyte"),i.push(`${e}#${o}`)):e.match(/\s?B/i)&&(e=e.replace(r,""),i.push(`${e}#${o}`)):i.push(`!X!Y!Z!#${o}`)}}(d,y),o.classList.contains("remember-sort")||function(e,i){i.push(t),1===e&&i.length>1&&i[i.length-1]!==i[i.length-2]&&(e=0,i.shift())}(b,u),b+=1,function(i,o,u,y){for(let[e,s]of i.entries()){let i=s.querySelectorAll("td").item(t).textContent;0===i.length&&(i=""),""!==i.trim()?(u&&(r[o[e]]=s.innerHTML),u||y||(o.push(`${i}#${e}`),n[`${i}#${e}`]=s.innerHTML)):(o.push(`!X!Y!Z!#${e}`),n[`!X!Y!Z!#${e}`]=s.innerHTML)}function d(e,t){return e.includes("X!Y!Z!#")?1:t.includes("X!Y!Z!#")?-1:e.localeCompare(t,navigator.languages[0]||navigator.language,{numeric:!0,ignorePunctuation:!0})}function m(e,t){return d(t,e)}function f(t="▲",i="▼"){e.innerText=e.innerText.replace(t,""),e.innerText=e.innerText.replace(i,"")}void 0!==o[0]&&(1===b?s?(l&&(f(a,c),e.insertAdjacentText("beforeend",c)),o.sort(m,{numeric:!0,ignorePunctuation:!0})):(l&&(f(a,c),e.insertAdjacentText("beforeend",a)),o.sort(d)):2===b&&(b=0,s?(l&&(f(a,c),e.insertAdjacentText("beforeend",a)),o.sort(d,{numeric:!0,ignorePunctuation:!0})):(l&&(f(a,c),e.insertAdjacentText("beforeend",c)),o.sort(m))))}(d,y,f,m),function(e,i,o){for(let[s,l]of e.entries())if(o){l.innerHTML=r[i[s]];let e=l.querySelectorAll("td").item(t).innerHTML,n=l.querySelectorAll("td").item(t).textContent;const o={Kibibyte:1024,Mebibyte:1049e3,Gibibyte:1074e6,Tebibyte:11e11,Pebibyte:1126e12};i[s]=i[s].replace(/#[0-9]*/,""),e=i[s]<o.Kibibyte?e.replace(n,`${parseFloat(i[s]).toFixed(2)} B`):i[s]>=o.Kibibyte&&i[s]<o.Mebibyte?e.replace(n,`${(i[s]/o.Kibibyte).toFixed(2)} KiB`):i[s]>=o.Mebibyte&&i[s]<o.Gibibyte?e.replace(n,`${(i[s]/o.Mebibyte).toFixed(2)} MiB`):i[s]>=o.Gibibyte&&i[s]<o.Tebibyte?e.replace(n,`${(i[s]/o.Gibibyte).toFixed(2)} GiB`):i[s]>=o.Tebibyte&&i[s]<o.Pebibyte?e.replace(n,`${(i[s]/o.Tebibyte).toFixed(2)} TiB`):e.replace(n,"NaN"),l.querySelectorAll("td").item(t).innerHTML=e}else o||(l.innerHTML=n[i[s]])}(d,y,f)}))}}"complete"===document.readyState||"interactive"===document.readyState?tableSortJs():"loading"===document.readyState&&document.addEventListener("DOMContentLoaded",tableSortJs,!1),"object"==typeof module&&(module.exports=tableSortJs); </script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.3/css/theme.blue.min.css" integrity="sha512-jJ9r3lTLaH5XXa9ZOsCQU8kLvxdAVzyTWO/pnzdZrshJQfnw1oevJFpoyCDr7K1lqt1hUgqoxA5e2PctVtlSTg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.3/js/jquery.tablesorter.min.js" integrity="sha512-qzgd5cYSZcosqpzpn7zF2ZId8f/8CHmFKZ8j7mU4OUXTNRd5g+ZHBPsgKEwoqxCtdQvExE5LprwwPAgoicguNg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.3/js/jquery.tablesorter.widgets.min.js" integrity="sha512-dj/9K5GRIEZu+Igm9tC16XPOTz0RdPk9FGxfZxShWf65JJNU2TjbElGjuOo3EhwAJRPhJxwEJ5b+/Ouo+VqZdQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>$(function(){$("table").tablesorter({theme:"blue",widthFixed:!0,widgets:["zebra","filter"],ignoreCase:!0})});</script>

<h1>--------PH_TITLE-------</h1>
<tt>Report Date: --------PH_DATE-------</tt>
Expand Down

0 comments on commit f6ef533

Please sign in to comment.