I am trying to build Alphabet base filter in LWC Datatable. I want to filter opportunity name based on the Alphabet pressed by the user i.e if letter 'A' is pressed then I should see only those opportunities where opportunity name starts with letter 'A' .This is where i am not able to find a solution how to filter the datatable based on the action of the user , I want to do this filter in js file as I already have the data which needs to be filtered. if somebody has implemented the same kind of functionality and can share the knowledge that will be helpful.
JS code snippet
handleLetterFilter(event){
this.allProducts = [...this.products];
let letter = event.target.text;
console.log('This is the letter ',letter);
if(letter != 'ALL'){
} else {
console.log('This is the length',this.allProducts.length);
}
}
HTML code Snippet
<ul class="slds-list_horizontal slds-has-block-links_space">
<li><a onclick={handleLetterFilter}>A</a></li>
<li><a>B</a></li>
<li><a>C</a></li>
<li><a>D</a></li>
<li><a>E</a></li>
<li><a>F</a></li>
<li><a>G</a></li>
<li><a>H</a></li>
<li><a>I</a></li>
<li><a>J</a></li>
<li><a>K</a></li>
<li><a>L</a></li>
<li><a>M</a></li>
<li><a>N</a></li>
<li><a>O</a></li>
<li><a>P</a></li>
<li><a>Q</a></li>
<li><a>R</a></li>
<li><a>S</a></li>
<li><a>T</a></li>
<li><a>U</a></li>
<li><a>V</a></li>
<li><a>W</a></li>
<li><a>X</a></li>
<li><a>Z</a></li>
<li><a onclick={handleLetterFilter}>ALL</a></li>
</ul>
lightning-datatable
documentation about filters that will be helpful (under Creating Header Actions).