Select Method
The select method is used to select data from a table.

Returns: ml.data.query.Query Syntax .select('*') and .select(columnName1,columnName2,columnName3, ...) Example
  1. var q = ml.query();
  2. q.select('LowRate').from('hms/hotels');
  3. q.run(function(data){
  4. console.log(data);
  5. });
Demo
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/JS"></script>
  4. <script type="text/javascript">
  5. ml.onload(function () {
  6. //create ml.query()
  7. var q = ml.query();
  8. q.select('Amount', 'State').from('maplarge/Donors');
  9. q.run(function (data, query) {
  10. //Show the data as an html table
  11. displayTable(document.getElementById("dataDiv"),data);
  12. });
  13. });
  14.  
  15. //Helper Function to Layout the Data
  16. function displayTable(dataDiv, data){
  17. var rows = ml.data.query.Query.transposeQueryData(data.data);
  18. console.log(rows);
  19. var head = [];
  20. ml.each(rows[0], function(k,v) {
  21. head.push(k);
  22. });
  23. rows.unshift(head);
  24. data=rows;
  25. var table = ml.$("<table/>").addClass('CSSTableGenerator');
  26. ml.$.each(data, function(rowIndex, r) {
  27. var row = ml.$("<tr/>");
  28. ml.$.each(r, function(colIndex, c) {
  29. var content = "<p>"+c+"</p>";
  30. row.append(ml.$("<t"+(rowIndex == 0 ? "h" : "d")+"/>").html(content));
  31. });
  32. table.append(row);
  33. });
  34.  
  35. ml.$(dataDiv).html(table);
  36. }
  37. </script>
  38. <style>
  39. table tr:nth-child(even) {
  40. background-color: #eee;
  41. }
  42. table tr:nth-child(odd) {
  43. background-color:#fff;
  44. }
  45. table th {
  46. background-color: black;
  47. color: white;
  48. padding: 4px;
  49. }
  50. table td {
  51. padding: 4px;
  52. }
  53. </style>
  54. </head>
  55. <body>
  56. <div id="dataDiv"></div>
  57. </body>
  58. </html>