1

I have stringfilters bind to my table of data.

What i would like to get from the stringfilter is to be able to search like you would do with queries.

There is a colomn with names - a name for each row - for example - "Steve","Monica","Andreas","Michael","Steve","Andreas",...

I want to have both rows with Monica and Steve from the StringFilter.


I would like to be able to search like this

Steve+Monica

or

"Steve"+"Monica"

or

"Steve","Monica"


This is one of my stringfilters:

    var stringFilter1 = new google.visualization.ControlWrapper({
    controlType: 'StringFilter',
    containerId: 'string_filter_div_1',
    options: {
        filterColumnIndex: 0, matchType : 'any' 
    }
});
Henrik Aronsson
  • 1,383
  • 9
  • 17
Niels
  • 635
  • 3
  • 9
  • 23

1 Answers1

1

I had a similar problem, and I ended up creating my own function for filtering my rows. I made an example with the function that you describe, but I'm not sure it's the best or the right way, but it works.
One flaw is that you need to type in the names exactly as they are entered, the whole name and with capital letters.

Fiddle, try to add multiple names separated with a "+" (and no spaces).

The function I added looks like this:

 function redrawChart(filterString) {
    var filterWords = filterString.split("+")
    var rows = []

    for(i = 0; i < filterWords.length; i++) {
        rows = rows.concat(data.getFilteredRows([{value:filterWords[i], column:0}]))
    }

    return rows
}

And the listener that listens for updates in your string input looks like:

google.visualization.events.addListener(control, 'statechange', function () {

    if (control.getState().value == '') {
        realChart.setView({'rows': null})
    }else{
        realChart.setView({'rows': redrawChart(control.getState().value)})
    }
         realChart.draw();
});

Probably not a complete solution, but maybe some new ideas and directions to your own thoughts.

Henrik Aronsson
  • 1,383
  • 9
  • 17
  • Thanks. I really would like to have another kind of solution, where it isn't so restricted. But i really appreciate your answer! – Niels May 21 '15 at 15:28
  • As the restriction lies in gooles getFilteredRows function, I created a variant of it, where instead of using their function, you check all the rows yourself with your filter. [Fiddle](http://jsfiddle.net/s52j49qd/7/), here you can see a bit of variation. Also removed the constrain with uppercasing. Though, I believe this won't work with cyrillic letters and such. Same as before, you separate search phrases with "+". More info about uppercase restrains can be found [here](http://stackoverflow.com/questions/2140627/javascript-case-insensitive-string-comparison) – Henrik Aronsson May 23 '15 at 10:41
  • And I'll also credit [this guys](http://stackoverflow.com/questions/9229645/remove-duplicates-from-javascript-array/15868720#15868720) post for the unique method. – Henrik Aronsson May 23 '15 at 10:42