Search code examples
google-app-maker

How do I open a dialog or page to a specific record in Google App Maker?


I have an "edit" button on each row in a table of records in Google App Maker.

When the user clicks this button I would like the dialog/page that opens to be editing the record the user clicked on.

Ideally, the answer would work with the showDialog() function.


Solution

  • Try creating a page fragment (say, named "EditDialog") that uses the same datasource as your table. Then set this page fragment to be opened as when you click the edit button:

    app.showDialog(app.pageFragments.EditDialog);
    

    Table clicks should automatically select that row of data, so this should be enough. In some cases, I've noticed that the selection happens too late, and the previously selected record might get used in the dialog.

    In this case, you might have to make sure that the selection actually happens before the dialog is opened. If I recall correctly, something in the sense of the following (as onClick) made it work for me (this might not be that smart of a solution though):

    var key = widget.datasource.item._key;
    widget.datasource.selectKey(key);
    app.showDialog(app.pageFragments.EditDialog);
    

    Hope this helps!

    EDIT: I found out that actually this work better when you make the selection to the datasource not through that widget you're clicking, but through its parents or straight to the datasource (app.datasources.ArbitraryDatasource.selectKey(key);).