I'm currently struggling with the following problem.
I'd like to create an expression that I can apply dynamically to the column that the gridView is sorted by. In particular I have a gridView for basketball stats that contains a gamesPlayed column and if I would like to sort by a given column (points, fouls, rebounds, etc.), I'd like the following expression to apply:
CASE WHEN gamesPlayed = 0 THEN 0 ELSE [fieldToSortBy] * 1.0 / gamesPlayed END AS _sortField
(the 1.0 is needed cause otherwise the result of [fieldToSortBy] / gamesPlayed will always be rounded to the next integer)
Furthermore, is there a way how to "predefine" the whole expression and then just set the fieldToSortBy so to say as an argument?
I starting working on something, but I didn't get further than this:
IExpression mul = new Expression(field, ExOp.Mul, 1.0);
IExpression exp = new Expression(mul, ExOp.Div, gpField);
IEntityField2 sortField = new EntityField2("_sortField", exp);
This doesn't check for whether gp = 0, and the expression also has to be created once the field is actually known instead of being created once independent of what the field might be.