Skip to content

Instantly share code, notes, and snippets.

@crobinson42
Created March 31, 2017 18:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crobinson42/2626ec0b66d18948faedb8617a615222 to your computer and use it in GitHub Desktop.
Save crobinson42/2626ec0b66d18948faedb8617a615222 to your computer and use it in GitHub Desktop.
Live filter input for Dillon task board
// tamper script to add a live filter input next to search
const $table = $('table.task-list')
const $tableBody = $table.find('tbody')
const $filterInput = $('<input type="search" placeholder="filter"/>')
const filterInput = inputText => {
if (!inputText || inputText.length < 3) {
$tableBody.find('tr.hidden').map((i, el) => {
$(el).removeClass('hidden')
})
return
}
// look for table rows that contain the text
const matches = $tableBody.find(`td:contains(${inputText})`)
if (!matches.length) return
// add hidden class to all rows
$tableBody.find('tr').each((i, el) => {
el.classList.add('hidden')
})
matches.map((i, el) => {
$(el).closest('tr').removeClass('hidden')
})
}
// add filter input
$('#searchTextBox').after($filterInput)
$filterInput.on('keyup', e => filterInput(e.currentTarget.value))
$filterInput.on('click', e => filterInput($(e.currentTarget).value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment