Filter table by letter

Filter table by letter



I want to sort a table with one column by beginning letter. So if I click e.g.
button 'e' the page should only show entries beginning with an 'e'.






That's not sorting though, that's filtering...

– Luca Kiebel
Sep 6 '18 at 14:22






can you show how you are populating your table? It is from a request, an array... Try to provide more information.

– Pedro Simão
Sep 6 '18 at 14:23






You have to tell us about the data structure used to build the table or ppl cant help you.

– JGoodgive
Sep 6 '18 at 14:24






please share code what you have tried so far

– Naga Sai A
Sep 6 '18 at 14:24






also a table with 1 column is an array and not much of a table. then just array.filter((cell) => cell.startsWith("e"));

– JGoodgive
Sep 6 '18 at 14:26




2 Answers
2



Assuming you have an array with your data, you can use javascript filter function. Something like:


var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter(word => word.charAt(0) == 'e');



Thats a filter,



You can store the value of those buttons



Ej. var filterValue = 'e'



And if you got an array of values, you can use the filter method.



var filteredArray = array.filter(a => a.startsWith(filterValue)).



And display that filtered array



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)