I am having some issues with applying a filter on a grid after reloading data. I have a grid with data loaded and a button that manipulates what is shown in the grid. The button calls this function:
function viewLatestClicked()
{
var val1 = mygrid.getFilterElement(0).value;
var val2 = mygrid.getFilterElement(1).value;
mygrid.clearAll();
if (document.getElementById("viewLatest").checked) {
mygrid.load(urlLatest);
} else {
mygrid.load(urlAll);
}
if (val1 != null)
{
mygrid.filterBy(0,va11);
}
}
This works all good, but the code to preserve the filter that is on the grid does not work. I found that if I do not call mygrid.clearAll(); the filter preservation works perfectly.
Unfortunately I need to call that method to reload the data in the grid.
Also if I change the code like this, where “bal” is a valid filter for the grid in the first column, it doesn’t work. Removing mygrid.clearAll(); causes the filter to work.
function viewLatestClicked()
{
mygrid.clearAll();
if (document.getElementById("viewLatest").checked) {
mygrid.load(urlLatest);
} else {
mygrid.load(urlAll);
}
mygrid.filterBy(0,"bal");
}
Am I doing something wrong or could this be a bug in the dhtmlxGrid?
I am using dhtmlxSuite_v36_pro_131108.
Your filters are in the header of the grid. If you call clearAll() you clear the data of the grid but header is still there and the filters are still applied.
you may unfilter your grid before the clearing the data.
For example:
function viewLatestClicked()
{
var val1 = mygrid.getFilterElement(0).value;
var val2 = mygrid.getFilterElement(1).value;
// add the following code
mygrid.getFilterElement(0).value="";
mygrid.getFilterElement(1).value="";
mygrid.filterByAll();
//end
mygrid.clearAll();
function viewLatestClicked()
{
var val1 = mygrid.getFilterElement(0).value;
//alert(val1);
var val2 = mygrid.getFilterElement(1).value;
mygrid.getFilterElement(0).value="";
mygrid.getFilterElement(1).value="";
mygrid.filterByAll();
mygrid.clearAll();
if (document.getElementById("viewLatest").checked) {
mygrid.load(urlLatest);
} else {
mygrid.load(urlAll);
}
if (val1 != null)
{
mygrid.getFilterElement(0).value=val1;
mygrid.filterByAll();
//alert(val1);
}
//if (val2 != null)
//{
// mygrid.getFilterElement(1).value=val2;
//}
}
The first column filter is cleared now and set now, but it still does not apply the filter after it is cleared.
If I click on the header column filter and tab out of it, the filter is applied. It is as if it is not calling the filter event.
I also tried mygrid.filterBy(0,val1) which also does nothing.