AppMaker - 在 Table 导航到最后一页

AppMaker - Navigate to Last Page on Table

场景: 我计算出 SQL returns 100 个结果。 添加了 table(由此计算得出 SQL)并将页面大小限制为 25 个结果。 这将生成 4 个页面。 寻呼机表单 AppMaker 运行良好(在页面之间导航)但我需要一个直接从第 1 页导航到第 4 页的按钮。 这可能吗? 有人对此有解决方案吗?

此致

如果您知道您的查询总是 returns 100 条记录并且您的页面大小总是 25 条记录,那么最简单的方法是确保您的按钮绑定到同一个数据源并附加以下 onClick 事件:

widget.datasource.query.pageIndex = 4;
widget.datasource.load();

如果您需要知道您的 table 有多少条目(在您的情况下,它似乎固定为 100,但可能会增加),您仍然可以做您想做的事:

例如假设您的 YOURPAGE 上的 table 依赖于名为 Customers.

的数据源
  1. 创建一个名为 CustomerCount 的新数据项,只有一个字段,名为 Count(整数)。

  2. 它的数据源将是一个 sql 查询脚本:

Select count(CustomerName) as Count from Customers

  1. 在您拥有 table 的页面上,添加一个自定义的 属性(例如名为 Count 整数类型)

  2. 在页面附加事件中,使用此自定义操作异步设置 属性:

app.datasources.CustomerCount.load(function() { app.pages.YOURPAGE.properties.Count = app.datasources.CustomerCount.count; app.datasources.Customers.query.pageIndex = @properties.Count / 25; app.datasources.Customers.datasource.load(); });

我过去曾成功尝试过类似的事情。

找到解决方案:

服务器脚本:

function CandidateCountRows() {
  var query = app.models.candidate.newQuery();
  var records = query.run();
  console.log("Number of records: " + records.length);
  return records.length;
}

在按钮代码中:

var psize = widget.datasource.query.pageSize;
var pidx = widget.datasource.query.pageIndex;
var posicao = psize * pidx;
var nreg = posicao;

google.script.run.withSuccessHandler(function(Xresult) {
    nreg = Xresult;  
    console.log('position: ' + posicao);
    console.log('nreg: ' + nreg);
    console.log('psize: ' + psize);
    console.log('pidx: ' + pidx);

    var i;
    for (i = pidx; i < (nreg/psize); i++) {    
      widget.datasource.nextPage();
    }
    widget.datasource.selectIndex(1);
}).CandidateCountRows();

这将允许导航到最后一页。