diff options
author | Alexander Kabui | 2020-12-08 04:40:52 +0300 |
---|---|---|
committer | Alexander Kabui | 2020-12-08 04:40:52 +0300 |
commit | 6b9627b7b3559a64c5523bad8b5b376ae786a69b (patch) | |
tree | d389f3179fd446539e721f0484a3b732f86f39ad | |
parent | 977e0068b4038e65c0a03c80c304adac9951507c (diff) | |
download | genenetwork2-6b9627b7b3559a64c5523bad8b5b376ae786a69b.tar.gz |
refactor filter datatable function
-rw-r--r-- | wqflask/wqflask/static/new/javascript/auto_hide_column.js | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/wqflask/wqflask/static/new/javascript/auto_hide_column.js b/wqflask/wqflask/static/new/javascript/auto_hide_column.js index 94bb8a90..f879e0d1 100644 --- a/wqflask/wqflask/static/new/javascript/auto_hide_column.js +++ b/wqflask/wqflask/static/new/javascript/auto_hide_column.js @@ -1,28 +1,23 @@ -function filterDatable(datatable){ - let visitedColumns=[] - let columnCount=datatable.columns().header().length; - let numberOfRows=datatable.data().length; - for (let i=0;i<numberOfRows;i++){ - if (visitedColumns.length==columnCount){ +function filterDatatable(datatable){ + let visitedFoundColumns=[] + let columnCount=datatable.columns().header().length; + let numberOfRows=datatable.data().length; + for (let i=0;i<numberOfRows;i++){ + if (visitedFoundColumns.length==columnCount){ + break; + } + let rowObj=datatable.rows(i).data()[0] + for(let col=0;col<rowObj.length;col++){ + if (visitedFoundColumns.length==columnCount){ break; } - let rowObj=datatable.rows(i).data() - rowObj.data().each(function(rowData,v){ - if (visitedColumns.length==columnCount){ - return false; - } - for (let j=0;j<rowData.length;j++){ - if (j in visitedColumns||visitedColumns.length==columnCount){ - break; - } - if (rowData[j]!="N/A" && rowData[j]!=""){ - - visitedColumns.push(j) - } - } - }) + if (visitedFoundColumns.includes(col) || rowObj[col]=="N/A"||rowObj[col]==""){ + continue; + } + visitedFoundColumns.push(col) } - emptyColumns=Array.from(Array(columnCount).keys()).filter((item)=>visitedColumns.indexOf(item)<0); - return datatable.columns(emptyColumns).visible(false); + } + emptyColumns=Array.from(Array(columnCount).keys()).filter((item)=>visitedFoundColumns.indexOf(item)<0); + return datatable.columns(emptyColumns).visible(false); -} +}
\ No newline at end of file |