.groupby(columnName.FirstLetter)
groupby FirstLetter provides the ability to group string columns by the first letter..groupby(columnName.FirstLetter: string)
and
.groupby(columnName.FirstLetterNoCase: string)
If columnName.key is in the select statement, the result data will contain an array of first letters.
var q = ml.query().from('Example/PopularGirlNames1'); q.select('Name.key', 'Name.count'); q.groupby('Name.FirstLetter').orderby('Name.count.desc'); q.run(function(data){ console.log(data); });
<html> <head> <script type="text/javascript" src="/JS"></script> <script type="text/javascript"> ml.onload(function () { var q = ml.query().from('Example/PopularGirlNames1'); // choose the columns to return q.select('Name.key', 'Name.count'); // group the data q.groupby('Name.FirstLetter').orderby('Name.count.desc'); // execute the query and process the return with the callback q.run(function(data){ console.log(data); //Show the data as an html table displayTable(document.getElementById("dataDiv"),data); }); }); function displayTable(dataDiv, data){ var rows = ml.data.query.Query.transposeQueryData(data.data); console.log(rows); var head = []; ml.each(rows[0], function(k,v) { head.push(k); }); rows.unshift(head); data=rows; var table = ml.$("<table/>").addClass('CSSTableGenerator'); ml.$.each(data, function(rowIndex, r) { var row = ml.$("<tr/>"); ml.$.each(r, function(colIndex, c) { var content = "<p>"+c+"</p>"; row.append(ml.$("<t"+(rowIndex == 0 ? "h" : "d")+"/>").html(content)); }); table.append(row); }); ml.$(dataDiv).html(table); } </script> <style> table tr:nth-child(even) { background-color: rgb(231, 231, 231) } table tr:nth-child(odd) { background-color:#fff; } table th { background-color: rgb(86, 110, 140); color: white; padding: 5px; } table td { padding: 5px; } </style> </head> <body> <div id="dataDiv"></div> </body> </html>