The JavaScript ml.query API provides advanced functions that may be used to query data from any table using a fluent interface and receive AJAX responses.
<html> <head> <script type="text/javascript" src="/JS"></script> <script type="text/javascript"> ml.onload(function () { var q = ml.query().from('maplarge/Donors').where('PartyCode', 'Contains', 'r').groupby('State'); q.select('State').select('Amount.sum').orderby('Amount'); q.run(function (data, query) { var dataDiv = document.getElementById('dataDiv'); dataDiv.innerHTML = ml.util.toJSON(data); }); }); </script> </head> <body> <div id="dataDiv"></div> </body> </html>
The Return Object from the server is a JSON object which contains 2 Objects, data and totals. The data object contains all non-aggregate data from the query. Grouped aggregate data is contained in the totals data object following the naming convention columnName_aggregateName.
Return Object Description
Property | Description |
---|---|
data | object containing return data { “data”: { “column1”:[“row1”,”row2”], “column2”:[“row1”,”row2”] }} |
totals | non grouped aggregated data { "column1_sum":[100] } |
Methods
Method | Description | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
start | Begin at this row number. Equivalent to the X in sql's LIMIT X,Y | ||||||||||||||||||||||||||
take | Limit response to this many rows. Equivalent to the Y in sql's LIMIT X,Y | ||||||||||||||||||||||||||
select | If set, will only return specific columns (excluding geographic columns). Values are comma delimited. The value "*" means all non-geo columns. To include aggregates: ex: select=*, Amount.sum, Amount.avg, Amount.unique, Amount.countIf omitted, will return all non-geographic columns in the table. | ||||||||||||||||||||||||||
groupby | If set, uses the value as a comma delimited list. No aggregate grouping. Aggregate functions count, avg, sum, unique are available. | ||||||||||||||||||||||||||
orderby | If set, orders output data by that column. Supports single. Append asc or desc to sort ascending or descending. If not set, default is ascending order. ex: orderby=Amount.desc | ||||||||||||||||||||||||||
where | Standard where clauses, as defined by the API.
|