Created
July 10, 2016 07:51
-
-
Save rattrayalex/8450e2378465e85ed846837a5d0114a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getIndex = (th) => Array.from(th.parentElement.children).indexOf(th) | |
const getChildren = (i) => Array.from(document.querySelectorAll(`td:nth-child(${i + 1})`)) | |
const setHiddenStyle = (node) => { | |
node.style.width = '1px' | |
node.style.overflow = 'hidden' | |
node.style.overflowWrap = 'normal' | |
} | |
const toggleHidden = (node) => { | |
if (node.style.length) { | |
node.style = {} | |
} else { | |
setHiddenStyle(node) | |
} | |
} | |
const handleClick = (e) => { | |
const i = getIndex(e.currentTarget) | |
getChildren(i).concat([e.currentTarget]).forEach(toggleHidden) | |
} | |
document.querySelectorAll('th').forEach(th => { | |
th.onclick = handleClick; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment