Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Michael on Dec 16, 2009 13:59
open dhtmlx forum
Filter DHTMLX Grid Through Dropdown vs. API

Hi,

I have a grid that loads XML via an ajax call to a php page. After the data loads, I can filter the grid through the api using the filterBy call. However, the grid also has filter dropdowns in the header, and I would like to filter the grid it in such a way that it displays the filtered item in the dropdown as well as filtering the grid, so that the user knows the grid is filtered and why.

The reason for this is that the user can set a data filter on the another page. After the filter is set, the site will remember the filter and data on any page the user visits should have the filter applied. So basically, if the filter is set, when they hit this page and it loads it pulls data into the grid via ajax, then it should filter the grid and display the filter in the grid's header dropdown filter.

The user should be able to remove the filter or change the filter using the the dropdown filters in the grid's header without additional ajax requests. In other words all the data should be retrieved and then the filter applied so that the user can slice and dice the data using the filters in the header - I don't want to restrict the data being sent from the database, I prefer to restrict the data in the client.

Is there an API or method that will let me do this? I haven't been able to figure this out.

Thanks,
Michael
Answer posted by dhxSupport on Dec 17, 2009 02:35
To set value to the header filter you can use getFilterElement() method.
http://dhtmlx.com/dhxdocs/doku.php?id=dhtmlxgrid:api_method_dhtmlxgridobject_getfilterelement
mygrid.getFilterElement(COLUMN_INDEX).value="some value"

To filter grid after you have set value for filters you can use filterByAll() method:
mygrid.load(url,function(){
 mygrid.filterByAll();
})
http://dhtmlx.com/dhxdocs/doku.php?id=dhtmlxgrid:api_method_dhtmlxgridobject_filterbyall

If you don't want to call additional ajax request while filtering you should not use dynamic loading and server side filtering.
Answer posted by Michael on Dec 17, 2009 15:18
Is it possible to drive one filtering element in a grid header off another element in the header.  As an example, I have two dhtmlxcombos in a dhtmlxgrid header.  The Combo A filters on column A, Combo B filters on column B.  Column B should be dependent on Column A.  Is it possible to have the list of items displayed in Combo B be dependent on what the user selected in Combo A?  If Item A in Combo A is picked, Combo should only display items from Column B that will be displayed after the filter.

Can this be done?

Thanks,
Michael
Answer posted by dhxSupport on Dec 18, 2009 02:18
It can be done with refreshFilter() mehtod and "onFilterEnd" event. Please find more information here http://dhtmlx.com/docs/products/kb/index.shtml?cat=search&page=1&q=11137&ssr=yes&s=refreshFilters