Domanda

I am trying to apply some custom client-side filtering to a Telerik MVC Grid (version 2012.3.1018). The Grid has a large number of rows, and the goal is to show only the rows that were entered by employees of a certain department. According to the documentation, "If you have more than two statements in your filter expression, you should declare them using parentheses." By trial and error, I determined that the Grid can handle filter conditions only in pairs, but each pair can contain other pairs.

So for example, if you have 4 possible conditions, you have to do something like:

(1 or 2) or (3 or 4)

The problem is that the parentheses start to get really complex when there are a large number of conditions. For 16, you need:

(((1 or 2) or (3 or 4)) or ((5 or 6) or (7 or 8))) or (((9 or 10) or (11 or 12)) or ((13 or 14)) or (15 or 16)))

In other words, the condition consists of 1 pair, with 1–8 in the left-handed group and 9–16 on the right.

I am having a devil of a time constructing the filter string. I've tried iterating through an array of the conditions, but I can't seem to get the parentheses correct: I'm either missing some or I have too many. I suspect I need some sort of tree structure, but as I don't have a computer science background, the solution eludes me. I've spent far too much time on this already.

Thanks in advance for any advice.

È stato utile?

Soluzione

The solution was to stack up all the parentheses on the left side:

((((((A or B) or C) or D) or E) or F) or G

It was in Applying rules in Telerik MVC Grid Filter but was not explained there, so I didn't quite catch it.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top