Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakhmadi committed Jun 21, 2021
1 parent 94a9560 commit 14e747d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
8 changes: 6 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class RdataTB {
const cv = document.getElementById(`${this.HeaderDataTable[n]}_header`);
document.getElementById(`${this.HeaderDataTable[n]}_header`).style.opacity = '100%';
cv.onclick = () => {
this.sort(`${this.HeaderDataTable[n]}`);
this.sort(this.HeaderDataTable[n]);
document.getElementById(`${this.HeaderDataTable[n]}_header`).style.opacity = '60%';
if (this.Assc) {
document.getElementById(`${this.HeaderDataTable[n]}_header`).classList.remove('tablesorter-header-asc');
Expand All @@ -337,12 +337,13 @@ class RdataTB {
* @returns show data shorted
*/
sort(column) {
const t0 = performance.now();
function naturalCompare(a, b) {
const ax = [];
const bx = [];
a.toString().replace(/(^\$|,)/g, '').replace(/(\d+)|(\D+)/g, function (_, $1, $2) { ax.push([$1 || Infinity, $2 || ""]); });
b.toString().replace(/(^\$|,)/g, '').replace(/(\d+)|(\D+)/g, function (_, $1, $2) { bx.push([$1 || Infinity, $2 || ""]); });
while (ax.length && bx.length) {
for (let index = 0; ax.length && bx.length; index++) {
const an = ax.shift();
const bn = bx.shift();
const nn = (an[0] - bn[0]) || an[1].localeCompare(bn[1]);
Expand All @@ -367,6 +368,9 @@ class RdataTB {
this.DataSorted = data;
this.i = 0;
this.RenderToHTML();
const t1 = performance.now();
this.timeSort = Math.round((t1 - t0) / 1000 * 10000) / 10000;
console.log("" + this.timeSort + " milliseconds.");
return this.DataSorted;
}
/**
Expand Down
21 changes: 13 additions & 8 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class RdataTB {
ListHiding:Array<string> = []
SelectionNumber: number[] = [5,10,20,50]
SelectElementString: string = '';
timeSort!: number;

/**
*
Expand Down Expand Up @@ -347,7 +348,7 @@ class RdataTB {

cv.onclick = ()=>{

this.sort(`${this.HeaderDataTable[n]}`);
this.sort(this.HeaderDataTable[n]);
document.getElementById(`${this.HeaderDataTable[n]}_header`)!.style.opacity = '60%'
if (this.Assc) {
document.getElementById(`${this.HeaderDataTable[n]}_header`)!.classList.remove('tablesorter-header-asc')
Expand All @@ -374,19 +375,20 @@ class RdataTB {
* @returns show data shorted
*/
public sort(column:string):Array<any>{
const t0:number = performance.now()
function naturalCompare(a:any, b:any) {
const ax:Array<any> = []
const bx:Array<any> = []

a.toString().replace(/(^\$|,)/g,'').replace(/(\d+)|(\D+)/g, function (_:any, $1:any, $2:any) { ax.push([$1 || Infinity, $2 || ""]) });
b.toString().replace(/(^\$|,)/g,'').replace(/(\d+)|(\D+)/g, function (_:any, $1:any, $2:any) { bx.push([$1 || Infinity, $2 || ""]) });
while (ax.length && bx.length) {
const an = ax.shift();
const bn = bx.shift();
const nn = (an[0] - bn[0]) || an[1].localeCompare(bn[1]);
if (nn) return nn;

for (let index = 0; ax.length && bx.length ; index++) {
const an = ax.shift();
const bn = bx.shift();
const nn = (an[0] - bn[0]) || an[1].localeCompare(bn[1]);
if (nn) return nn;
}

return ax.length - bx.length;
}
const data = this.DataTable
Expand All @@ -404,6 +406,9 @@ class RdataTB {
this.DataSorted = data
this.i = 0
this.RenderToHTML()
const t1:number = performance.now()
this.timeSort = Math.round((t1 - t0)/1000*10000)/10000
console.log("" + this.timeSort+ " milliseconds.")
return this.DataSorted
}

Expand Down

0 comments on commit 14e747d

Please # to comment.