Search code examples
javascriptgoogle-app-maker

How can I sort a list by month in App Maker?


I want to sort a list in App Maker by month, and I don't know how to it.

enter image description here

I think that was the way, but is not.

@datasource.item.MONTH#sort()

Solution

  • I am not sure how many ways there are to achieve this but here are two ways:

    First one: Go the the model datasource and change the sorting option to reflect the month and then choose by ascending or descending. See the example below. enter image description here

    Second one: Select the table widget and the go to the events section in the Property Editor. Click on the onDataLoad event and type the following code:

    widget.datasource.items.sort(
      function(a, b) {
        if (a.Month > b.Month) {
          return 1;
        } else {
          return -1;
        }
      }
    );
    

    See the image below: enter image description here

    Whichever way you prefer, is your choice. Hope it helps!

    Note: the second option will sort only records withing single page currently loaded to the client.