Created
March 31, 2017 18:05
-
-
Save crobinson42/2626ec0b66d18948faedb8617a615222 to your computer and use it in GitHub Desktop.
Live filter input for Dillon task board
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
// 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