/// <summary> /// Adds client total calculator that produces count of rows /// </summary> /// <param name="conf">Configuration</param> /// <param name="column">Table column to provide total with</param> /// <param name="clientDataSet">Client data set to perform calculations on</param> /// <param name="template">Tempalte for total cell</param> /// <returns></returns> public static TotalCalculatorBuilder <TSourceData, TTableData> AddClientCount <TSourceData, TTableData, TTableColumn>( this TotalCalculatorBuilder <TSourceData, TTableData> conf, Expression <Func <TTableData, TTableColumn> > column, ClientDataSet clientDataSet, Action <CellTemplateBuilder> template = null ) where TTableData : new() { var name = LambdaHelpers.ParsePropertyLambda(column).Name; var function = string.Format("function(v){{ return v.{0}.length; }}", clientDataSet); conf.ClientCalculators.Add(name, function); if (template != null) { conf.AddTemplate(column, template); } return(conf); }
/// <summary> /// Adds client total calculator that produces maximum of supplied row values /// </summary> /// <param name="conf">Configuration</param> /// <param name="column">Table column to provide total with</param> /// <param name="expression">`{@}`-syntax expression minimum of which will be found</param> /// <param name="clientDataSet">Client data set to perform calculations on</param> /// <param name="template">Tempalte for total cell</param> /// <returns></returns> public static TotalCalculatorBuilder <TSourceData, TTableData> AddClientMax <TSourceData, TTableData, TTableColumn>( this TotalCalculatorBuilder <TSourceData, TTableData> conf, Expression <Func <TTableData, TTableColumn> > column, string expression, ClientDataSet clientDataSet, Action <CellTemplateBuilder> template = null ) where TTableData : new() { var name = LambdaHelpers.ParsePropertyLambda(column).Name; var function = CreateExtremumFunction(expression, true, clientDataSet); conf.ClientCalculators.Add(name, function); if (template != null) { conf.AddTemplate(column, template); } return(conf); }
/// <summary> /// Provides table with totals row representing subtotals for particular columns /// </summary> /// <param name="calculators">Totals calculator builder</param> /// <param name="showOnTop">When true, totals line will be shown before data on current page. When false, it will be shown on the bottom of them</param> /// <returns></returns> public static Configurator <TSourceData, TTableData> Totals <TSourceData, TTableData>( this Configurator <TSourceData, TTableData> conf, Action <TotalCalculatorBuilder <TSourceData, TTableData> > calculators, bool showOnTop = false ) where TTableData : new() { TotalCalculatorBuilder <TSourceData, TTableData> calc = new TotalCalculatorBuilder <TSourceData, TTableData>(); calculators(calc); TotalClientConfiguration tcc = new TotalClientConfiguration() { ShowOnTop = showOnTop, ColumnsValueFunctions = calc.ValueFunctions.ToDictionary(c => c.Key, v => v.Value != null ? new JRaw(v.Value) : null), ColumnsCalculatorFunctions = calc.ClientCalculators.ToDictionary(c => c.Key, v => v.Value != null ? new JRaw(v.Value) : null) }; conf.TableConfiguration.ReplacePluginConfig(PluginId, tcc); var trr = new TotalResponseModifier <TSourceData, TTableData>(calc); conf.RegisterResponseModifier(trr); return(conf); }
public TotalResponseModifier(TotalCalculatorBuilder <TSourceData, TTableData> calculator) { _calculator = calculator; }