How to implement sqlalchemy aggregate functions in flask datatables (Server Side)?
Got help from https://github.com/Pegase745/sqlalchemy-datatables/issues/93. The key thing to notice here is the global_search = False parameter. If it is not used, it throws error in where clause saying aggregate functions cannot be used in Where clause..
columns = [ ColumnDT(Timepass.user_name), ColumnDT(func.sum(Timepass.income).label('Sum'), global_search=False), ColumnDT(func.count(Timepass.user_name).label('Count'), global_search=False)]query = session.query(Timepass.user_name, func.sum(Timepass.income).label('Sum'), func.count(Timepass.user_name).label('Count')).group_by(Timepass.user_name)params = request.args.to_dict()rowTable = DataTables(params, query, columns)return jsonify(rowTable.output_result())