JavaScript UI Libraries & Blazor Components Suite – Smart UI › Forums › Data Grid › Filter Editor clear filter button › Reply To: Filter Editor clear filter button
Hi Dark Beccio,
Yes you can add a button to clear the grid filters. For your case I can suggest three options and you can choose which one you will fit your needs the best.All of the solutions use the clearFilter()
methods which clears all all filtering on the grid.
Option 1 which in my opinion is the most clean solution is to clear the filter when the ‘smart-input’ value is empty string.
Example:
input.addEventListener('change', () => {
if (input.value === '') {
grid.clearFilter();
} else {
column.filter = 'equal "' + input.value.trim() + '"';
}
});
Option 2 is to add the button in the filterEditor
template after the smart-input
component in the filter row, but I don’t recommend this option because UI point of view.
Example:
//In the filterEditor template:
filterEditor: {
template: '<smart-input drop-down-button-position="right" placeholder="Azienda" style="border-radius: 0px; border: none; width: 50%; height:100%"></smart-input><smart-button >Clear</smart-button>',
onInit(column, editor) {
const input = editor.querySelector('smart-input');
const productNames = comboAziendeJson;
let result = [];
for (let d = 0; d < productNames.length; d++) {
result.push((productNames[d].Dex));
}
const btn= editor.querySelector('smart-button')
btn.addEventListener('click', ()=>{
grid.clearFilter();
})
Option 3- to add a button outside the grid component to clear the filters.
Example:
//In your HTNML file
<smart-grid id="grid"></smart-grid>
<smart-button id='clearFilterButton'>Clear Filter</smart-button>
//In your Js file
window.onload = function () {
const grid = document.getElementById('grid');
const clearFilterButton = document.getElementById('clearFilterButton');
clearFilterButton.addEventListener('click', ()=>{
grid.clearFilter();
})
};
Please, do not hesitate to contact us if you have any additional questions.
Best regards,
Yavor Dashev
Smart UI Team
https://www.htmlelements.com/