Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by rchang on Jul 15, 2008 12:25
open dhtmlx forum
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.

Answer posted by Support on Jul 16, 2008 02:38
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();
Answer posted by rchang on Jul 16, 2008 12:50

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: <body onload="doInitGrid();">

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

Answer posted by Support on Jul 17, 2008 06:15
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();
}
Answer posted by rchang on Jul 17, 2008 06:26
That works!  Thanks again!