I would say it wasn't an easy task.
But here is how it could be solved:
- As you already mentioned
quickFilter
is a clientSide
model type feature
- But no one has cancelled the
setFilterModel
way of usages
It would require a lot of hacks and could break something (you have to check it on your solution and write a feedback then)
First of all, setFilterModel
can't work with virtual data (we have to define column
especially for quickFilter
logic)
{
field:'-', would be used as a reference
hide:true, - hide in grid data
lockVisible:true, - disable visibility changing via menu
filter:"agTextColumnFilter", - require for setFilterModel
filterParams:{
newRowsAction: "keep"
}
},
Next, we need to create a workaround for filterModel
in datasource
getRows: function(params) {
setTimeout(function() {
var dataAfterSortingAndFiltering = sortAndFilter(data, params.sortModel, params.filterModel);
var rowsThisPage = dataAfterSortingAndFiltering.slice(params.startRow, params.endRow);
var lastRow = -1;
if (dataAfterSortingAndFiltering.length <= params.endRow) {
lastRow = dataAfterSortingAndFiltering.length;
}
params.successCallback(rowsThisPage, lastRow);
}, 3000);
}
function sortAndFilter(allOfTheData, sortModel, filterModel) {
return sortData(sortModel, filterData(filterModel, allOfTheData));
}
function sortData(sortModel, data) {
... sort logic here (doesn't matter for now) ...
}
Now about quickFilter
logic, we've defined dummy
column for it and here how it should be used:
setFilterModel will accept only existing column name ("-" in our case)
and with limited object props: but we will use filter
(as it used in real cases)
applyFilter(){
this.gridApi.setFilterModel({"-":{filter: this.filterText}})
}
and the last point of implementation is filterData
function
function filterData(filterModel, data) {
let filterPresent = filterModel && Object.keys(filterModel).length > 0;
if (!filterPresent) { - if filter model is empty - skip it
return data;
}
data = data.filter(i=>{
if(Object.keys(i).some(k => i[k] && i[k].toString().toLowerCase().includes(filterModel['-'].filter)))
return i;
})
return data;
}
Each object would be explored, and if any property contains quickFilter
value - it would be in the result
Moreover, once you will scroll out of existing range (infinite scroll case) requested data would be filtered by this property
*not sure about duplicated data check on request
My sample
Your modified sample