setting filters in grid

I am using dhtmlxgrid with filters in the headers, but I would like to pre-select a filter using code when the page loads. How can I achieve this?



Example:



mygrid = new dhtmlXGridObject(‘mygrid_container’);

mygrid.setHeader(“Col A, Col B”);

mygrid.attachHeader("#master_checkbox,#select_filter");



// set Col B to filter on the text “Foo”

mygrid.headerFilters(2,“Foo”) <---- what would this code be…





Thanks in advance for your help.



There is no build in methods to access filter inputs in header, it can be done through DOM, similar to next

var input = mygrid.hdr.rows[2].cells[1].getElementsByTagName(“SELECT”)[0];
input.value=“Foo”;
mygrid.filterByAll();


This is not working when I attach it to my initialization function which is coupled to the page load event.  This is what I tried… but the filter doesn’t seem to activate as Foo.  In fact all the options disappear under that filter.



in my HMTL i have:



in my JS I have:



function doInitGrid() {
   mygrid = new dhtmlXGridObject(‘mygrid_container’);
   mygrid.setHeader(“Col A, Col B”);
   mygrid.attachHeader("#master_checkbox,#select_filter"); 

   mygrid.init();
   mygrid.loadXML(visitXMLfile);

   var input = mygrid.hdr.rows[2].cells[1].getElementsByTagName(“SELECT”)[0];
   input.value=“Foo”;
   mygrid.filterByAll();
}



 



If I couple the filter selection code to a button it appears to work.  Can you tell me how to solve this?



Thanks

Please, try to call filtering when grid xml is loaded.

mygrid.loadXML(visitXMLfile,doOnLoad)

function doOnLoad(){
   var input = mygrid.hdr.rows[2].cells[1].getElementsByTagName(“SELECT”)[0];
   input.value=“Foo”;
   mygrid.filterByAll();
}

That works!  Thanks again!