在Google脚本中创建一个可排序的html表

时间:2012-07-25 01:48:26

标签: google-apps-script html-table

使用Google脚本我有一个HTML表格,并希望列可以排序。

有没有办法用sortable或tablesorter jQuery插件执行此操作,因为我没有看到如何调用这些而不在我自己的公共服务器上托管它们,我认为没有办法将它们包含在Google的js文件夹中脚本?

1 个答案:

答案 0 :(得分:1)

由于您使用的是Google脚本,因此您可以通过Default Services获得Google Visualization API。这包括TableChartBuilder,它可以产生您要询问的结果。

以下为an example,基于Visualize Your Data: Charts in Google Apps Script!中的图表示例,其中还说明了如何发布图表。

function doGet() {    
  // Populate the DataTable.  We'll have the data labels in   
  // the first column, "Release", and then add two data columns,  
  // for "Income" and "Expenses"  
  var dataTable = Charts.newDataTable()      
        .addColumn(Charts.ColumnType.STRING, "Release")      
        .addColumn(Charts.ColumnType.NUMBER, "Income")      
        .addColumn(Charts.ColumnType.NUMBER, "Expenses")      
        .addRow(["1.0", 60, 55])      
        .addRow(["10.2", 50, 60])      
        .addRow(["2.10", 100, 50])
        .addRow(["12.0.1", 70, 60])      
        .addRow(["2.0.0.142", 30, 50])
        .addRow(["2.0.0.1_2", 114, 75])
        .build();

  // Build the chart. 
  var chart = Charts.newTableChart()
      .setDataTable(dataTable)  
      .build();

  // Add our chart to the UI and return it so that we can publish  
  // this UI as a service and access it via a URL.  
  var ui = UiApp.createApplication();  
  ui.add(chart);  
  return ui;
}