Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Luke on May 24, 2009 05:33
open dhtmlx forum
Combo Filter Default Value

Hi guys, I've pasted my code below and I'm stuck getting the combo filter default value set. Can someone assist me with doing so or advise if I'm missing something. Thanks for your help.

The code I was given is below, but I'm not to sure where to put it or how to call it - I want my country value for example to default to Australia.
mygrid.load(ulr,function(){
           mygrid.getFilterElement(6).value="Australia"
           mygrid.filterByAll();
})


<script>


  var mygrid;
  var mygridQString = "getgridrecords.php";
 
  function doInitGrid(){
   mygrid = new dhtmlXGridObject('mygrid_container');
   mygrid.setImagePath("dhtmlxGrid/dhtmlxGrid/codebase/imgs/");
   mygrid.setHeader("val1,val2,val3,val4,val5,Country,val6,val7,val8,val9");

   //Used when DB gets to big!
   mygrid.attachHeader("#connector_text_filter,#connector_select_filter,#connector_select_filter,#connector_select_filter,,#connector_select_filter,#connector_select_filter,#connector_select_filter,#connector_text_filter,");
   mygrid.setColSorting("connector,connector,connector,connector,connector,connector,connector,connector,connector,connector");
   /*Used for basic table.
   mygrid.attachHeader("#select_filter,,#select_filter,#select_filter,#select_filter,#numeric_filter,");
   */
   
   mygrid.setInitWidths("60,40,70,210,210,*,*,*,80,40");
   mygrid.setColTypes("ro,ro,ro,ro,ro,ro,ro,ro,ro,ro");
   mygrid.setColAlign("left,left,left,left,left,left,left,left,right,left");
   mygrid.setColSorting("str,str,str,str,str,str,str,str,int,")
   mygrid.setSkin("light");
   mygrid.init();
   
   mygrid.enableSmartRendering(true);
   mygrid.loadXML(mygridQString);  

  } 

</script>
Answer posted by Support on May 25, 2009 03:47
The code which you are using is correct and will work correctly for normal select filters. 
The problem is that connector 0.9 requires additional server side code to fill the select-boxes with options ( currently your code correctly sets value, but it doesn't change anything - because selectboxes has no options defined ) 

In next few weeks, updated version of dhtmlxConnector will be released, which will allow more easy way of select filter usage ( it will not require any additional code and will fill select filters automatically - so your current code will work with it correctly ) 
If you need update ASAP - you can try to use attached codebase instead of original one
Attachments (1)
Answer posted by dhxSupport on May 25, 2009 04:02
If you are using data base from the dhtmlxConnector_php\samples\ folder, your code should looks like that:
mygrid.load(ulr,function(){
  mygrid.getFilterElement(6).value="Australia "
  mygrid.filterByAll();
})


Answer posted on May 25, 2009 05:01
Thanks for the attached file, I tried this codebase and I got 'Empty Stack' Error before making any changes to my working grid., obviously not 100% compatible. Any tips on getting this to work or should I wait? The table is used on a web page and I'm keen to launch it soon so wondering how long before final realease of what you mention is available.

I'm still not 100% sure on my code if the above is correct where do I place it.? Is it placed in the function doInitGrid area? like below? I could find references to this but I searched my PC for examples but nothing could be found. I looked in my samples folder but I must have deleted the sample because I can't find one.

<script>


  var mygrid;
  var mygridQString = "getgridrecords.php";

 
  function doInitGrid(){
   mygrid = new dhtmlXGridObject('mygrid_container');
   mygrid.setImagePath("dhtmlxGrid/dhtmlxGrid/codebase/imgs/");
   mygrid.setHeader("val1,val2,val3,val4,val5,Country,val6,val7,val8,val9");

   //Used when DB gets to big!
   mygrid.attachHeader("#connector_text_filter,#connector_select_filter,#connector_select_filter,#connector_select_filter,,#connector_select_filter,#connector_select_filter,#connector_select_filter,#connector_text_filter,");
   mygrid.setColSorting("connector,connector,connector,connector,connector,connector,connector,connector,connector,connector");
   /*Used for basic table.
   mygrid.attachHeader("#select_filter,,#select_filter,#select_filter,#select_filter,#numeric_filter,");
   */
   
   mygrid.setInitWidths("60,40,70,210,210,*,*,*,80,40");
   mygrid.setColTypes("ro,ro,ro,ro,ro,ro,ro,ro,ro,ro");
   mygrid.setColAlign("left,left,left,left,left,left,left,left,right,left");
   mygrid.setColSorting("str,str,str,str,str,str,str,str,int,")
   mygrid.setSkin("light");
   mygrid.init();
   
   mygrid.enableSmartRendering(true);
   mygrid.loadXML(mygridQString);  

mygrid.load(ulr,function(){
           mygrid.getFilterElement(6).value="Australia"
           mygrid.filterByAll();
})


  } 

</script>
Answer posted by dhxSupport on May 25, 2009 07:14
>>obviously not 100% compatible
Technically it must be 100% compatible for the grid.  We will prepare and send working sample by email. 

>>I'm still not 100% sure on my code 
Instead of using 

mygrid.loadXML(mygridQString);  

mygrid.load(ulr,function(){
  mygrid.getFilterElement(6).value="Australia"
  mygrid.filterByAll();
})

you need to use

mygrid.load(mygridQString,function(){
  mygrid.getFilterElement(6).value="Australia"
  mygrid.filterByAll();
})


Answer posted on May 25, 2009 14:36
Thank you for that, the code executes fine now, obviously the default isn't working with the old codebase but that's a good start.
FYI The error I get when trying to use the new codebase is below.

<www.example.com>

<br />
<b>Fatal error</b>:  Uncaught exception 'Exception' with message 'Source of data can't be empty' in /home/content/l/u/k/luke/html/dhtmlxGrid/dhtmlxConnector_php/codebase/db_common.php:95
Stack trace:
#0 /home/content/l/u/k/luke/html/dhtmlxGrid/dhtmlxConnector_php/codebase/db_common.php(119): DataRequestConfig-&gt;set_source('')
#1 /home/content/l/u/k/luke/html/dhtmlxGrid/dhtmlxConnector_php/codebase/base_connector.php(248): DataRequestConfig-&gt;parse_sql('SELECT table.val1...')
#2 /home/content/l/u/k/luke/html/getgridrecords.php(97): Connector-&gt;render_sql('SELECT table.val1...', 'val2', 'val3,val4...')
#3 {main}
  thrown in <b>/home/content/l/u/k/lukehepburn/html/dhtmlxGrid/dhtmlxConnector_php/codebase/db_common.php</b> on line <b>95</b><br />
Answer posted by Support on May 26, 2009 01:58
If it possible - please send full SQL text, used inside render_sql, to support@dhtmlx.com; it seems that code was not able to locate table name, used inside your SQL code.