How to get length of category filter values array?

83 views
Skip to first unread message

T-Roy

unread,
Jul 6, 2012, 11:01:14 AM7/6/12
to google-visua...@googlegroups.com
I am trying to get this code to work on a category filter:

     google.visualization.events.addListener(personPicker, 'ready', function(){
          //alert('modify personPicker visibility');
          var categoryValues = personPicker.getOption('values');
          alert(categoryValues);
//categoryValues is always null ???
          if (categoryValues){
               numpersons = categoryValues.length();
          }else{
               numpersons = 1;
          }
          alert('numpersons='+numpersons);
          if(numpersons>1){
               $('div#personfilter').css('display','inline-block');
               $('div#personfilter').css('visibility','visible');
          }else{
               $('div#personfilter').css('display','none');
               $('div#personfilter').css('visibility','hidden');
          }
     });


How/When can I get the number of items in the category filter?

Thanks?

asgallant

unread,
Jul 6, 2012, 11:28:08 AM7/6/12
to google-visua...@googlegroups.com
The #getOption method only returns options that you set - there is no way to get the specific list of values from the control (at least, not according to the documentation).  You can, however, group the DataTable on the filtered column to get the total number of unique values, and use that instead:

google.visualization.events.addListener(personPicker'ready'function({
    // get column index, can also use filterColumnLabel, if you set that option instead
    // if you use filterColumnLabel, you will need to translate it back into an index for the group
    var columnIndex personPicker.getOption('filterColumnIndex');
    var group google.visualization.data.Group(data[columnIndex]);
    
    var numpersons group.getNumberOfRows();
    
    alert('numpersons=' numpersons);
    if (numpersons 1{

        $('div#personfilter').css('display''inline-block');
        $('div#personfilter').css('visibility''visible');
    else {
        $('div#personfilter').css('display''none');
        $('div#personfilter').css('visibility''hidden');
    }
}); 

T-Roy

unread,
Jul 6, 2012, 4:08:08 PM7/6/12
to google-visua...@googlegroups.com
Excellent - Nice workaround.  Thank you!
Reply all
Reply to author
Forward
0 new messages