MTrinder wrote:
You can use an expression in a sort clause - please see the documentation here
Beyond that, I'm not quite sure what you're asking - perhaps you could give it a go, and then come back to us with any more specific questions...?
Matt
I looked through the part of the docu that you suggested and I could do something like this:
EntityField2 sortField = new EntityField2("sortField", new Expression(MyEntityFields.ColA, ExOp.Add, MyEntityFields.ColB));
SortClause sorter = new SortClause(sortField, null, SortOperator.Ascending);
But is there a way that I can just generate a SortClause from an expression given in a string? Meaning something along the lines of:
EntityField2 sortField = new EntityField2("sortField", "ColA + ColB");
SortClause sorter = new SortClause(sortField, null, SortOperator.Ascending);
What I am trying to achieve is an universal concept of creating GridView fields that will make me able to
a) calculate values of cells based on values of other cells in the same row,
b) sort the underlying LGP data source through a sort clause
c) and sort the column of the GridView based on the expression
The problem with the Expression is that even if I am able to calculate the values of the left and right operand (assuming that they are EntityFields), I am not really able to calculate the result of the expression in a reasonable way since the operator is not really universal (can only be used to generate a query text).
protected double getFieldValue(DataRowView dataItem)
{
// get the expression from the entity field associated grid view field
IExpression exp = this.DbField.ExpressionToApply;
// get the values of the left and right operand of the expression
double leftValue = getOperandFieldValue(dataItem, exp.LeftOperand); // e.g. = 2
double rightOperand = getOperandFieldValue(dataItem, exp.RightOperand); // e.g. = 3
ExOp operator = exp.Operator; // e.g. ExOp.Add
double result = operator.Evaluate(leftValue, rightValue); // e.g. 2 + 3 = 5
return result;
}
I'm not even able to figure out how to transform the expression in a string using .ToQueryText(). This way I could possible try using this for some functionalities offered by the DataTable class.