Sort A to Z click button on appinventor

Its possible to google sheet Column data Sort A to Z from Appinventor?

Yes, but you will need a google apps script setup to do it....

Some ideas

var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheets()[0];
 var range = sheet.getRange("A1:C7");

 // Sorts by the values in the first column (A)
 range.sort(1);

 // Sorts by the values in the second column (B)
 range.sort(2);

 // Sorts descending by column B
 range.sort({column: 2, ascending: false});

 // Sorts descending by column B, then ascending by column A
 // Note the use of an array
 range.sort([{column: 2, ascending: false}, {column: 1, ascending: true}]);

ref

2 Likes

That's fine, but it will always be active But I want to use buttons, which means I will have 2 buttons for 2 columns Clicking on the 1st button will sort by the 1st column. Clicking the 2nd button will sort the column by 2nd I hope I understand It will be possible to do.

Yes, that is possible. You need to set if/else in your script and send an identifying parameter to the script so that it knows which command to run.

1 Like

Please tell me details.

Here is a simple google apps script web app that does what you ask:

function doGet(e) {
 var ss = SpreadsheetApp.openById('1IdpGILd7Nii82xbDN1Cok');
 var sheet = ss.getSheetByName('Sheet1');
  var range = sheet.getRange('A2:H101');

  if (e.parameter.fn == 'ColA') {
 // Sorts by the values in the first column (A)
 range.sort(1);
 return ContentService.createTextOutput('ColA sorted')
  }
  else if (e.parameter.fn == 'ColB') {
 // Sorts by the values in the second column (B)
 range.sort(2);
 return ContentService.createTextOutput('ColB sorted')
  }
}

You would send a web Get from the app like this(to sort by ColA/1st column):

https://script.google.com/macros/s/AKfycmeMxdVe1aqMo/exec?fn=ColA
2 Likes

The script was able to realize. But what to do to block?

1 Like

Timai2 always master class in gsheet.

By the way why don't you refer his site for using gviz method of gettingdata from gsheet in whatever format you want? I mean , even if gsheet have whatever order you can get sorted order of all data or particular range from gsheet to mit app

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.