I've done this before in dojo framework + dgrid. Our system is based off of a dynamic metamodel where users define classes (e.g. Task) and attributes under those classes (e.g. State, owner, project reference) from a set of predefined types (e.g. Enum, user, reference). The defined metamodel ends up as a class hierarchy and is presented as a tree for the query builder. After defining a class, you can then instantiate that class and set attribute values on it.
For building queries, you drag classes and attributes from the metamodel tree into either the filter tree or the report fields section. The filter tree is a tree of AND's and OR's constructed as you drag attributes into it. Selecting an item in the filter tree then brings up a value editor based on the attribute type that allows you to filter your query based on values that make sense for that type. So if you define your tasks state as enum(unassigned, assigned, started, completed) you get a combo box with those values and options to select in, not in, null, etc.
The report fields section is a list of attributes you want to see in the result set. Basically just a select on that attributes value for the query system. Imagine a todo list created instantly by filtering on tasks with owner == current user and state not in completed, but also wanting to see and sort on the priority, and not showing the owner since you know it's you. The report fields area allows setting of sort order, and ascending or descending.
As you drag attributes into the filter or fields sections, a results pane underneath automatically gets new columns added (for fields added of removed) or new results based on a modified filter tree. After saving a query, users can then register for updates of items that match the query. If any data is changed that affects query results, the updated item or removal is pushed via websocket and that item is updated or removed from the results grid. With this, users never have to refresh the query since all the data is live.
Screenshots are slightly edited and a little out of date, but you get the idea.
Query builder: http://i.imgur.com/AV071JV.png
Dashboard (powered by query/report building): http://i.imgur.com/BvBW7L3.png