Search code examples
google-app-maker

How can I get grid-cell-collections from grid object?


How can I iterate all grid-cell panels in currentPage from the top of panel widget object?

I cannot understand how to get cell-panel collections from grid object.

for (var cell in widget.decendants.MyGridWidget.???) {
    cell.decendants.somethingOperation;
}

Solution

  • The setup to hide all detail panels for a grid would be as follows:

    GridPanel Cell (i.e. children):

    1. Header panel with a label widget and button widget (name: Button3). Set Button3 text to 'expand_less' initially.

    2. Detail panel with three label widgets.

    Code for onClick event for Button3:

    var grid = widget.parent.parent.parent;
    var cells = grid.children._values;
    cells.forEach(function(i) {
      if(i.descendants.Button3.text === 'expand_less') {
        i.descendants.Button3.text = 'expand_more';
      } else {
        i.descendants.Button3.text = 'expand_less';
      }
    });
    

    Detail Panel visibility binding:

    @widget.parent.descendants.Button3.text === 'expand_less'
    

    Hope something like this will work for your specific use case.