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'.
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.
That's not sorting though, that's filtering...
– Luca Kiebel
Sep 6 '18 at 14:22