Google App Maker: How to add pagination and sortin

2019-08-30 05:15发布

I have "Calculated" model called "Groups" in which I have added the following server script to load the google groups that are part of my domain and display them in a table widget when the user lands on the page. The data displays fine on the first page, but when I click to see the next page, I see the same subset of records and clicking the headers to sort the table does not work either. I'd appreciate some guidance here.

Calculated Model Server script:

var groupList = [];  
var pageToken;
 var page;
  do {
    page = AdminDirectory.Groups.list({
      customer: 'my_customer',
      maxResults: 5,
      pageToken: pageToken
    });

    var groups = page.groups;
    if (groups) {
      for (var i = 0; i < groups.length; i++) {
        var group = groups[i];
        var record = app.models.Groups.newRecord();
        
        record.id = group.id;
        record.name = group.name;
        record.email = group.email;
        record.directMembersCount = group.directMembersCount;
        
        groupList.push(record);
               
      }
    } else {
      console.log('No groups found.');
    }
    pageToken = page.nextPageToken;
    } while (pageToken);
return groupList;

I've configured the model the following way: enter image description here

0条回答
登录 后发表回答