Veso Yanchev
Veso Yanchev

Reputation: 29

How to force load and item by key in form?

The case

1 - I have an accordion widget with datasource Tasks.
2. - I have a form to display info on a selected Task. It has a datasource TaskByKey.

The sought solution:

What I tried:

I tried implementing the solution given as an example in Google's template, Project Tracker:

/**
 * Navigates user to the specific project view page.
 * @param {!string} projectKey - project key to view.
 * @param {boolean=} forceReplace - optional flag that forces to replace URL
 *     state in cases when state push would be normally used.
 */
function gotoViewProjectPageByKey(projectKey, forceReplace) {
  var params = {
    projectKey: projectKey
  };

  gotoViewProjectPageByParams(params, forceReplace);
}

Of course the above example targets a page, where as I want to change the datasource of an element on the same page.

TLDR

How can I set the onClick event of a button to load an item by key from datasource_X to datasource_X_byKey?

Upvotes: 0

Views: 48

Answers (1)

Morfinismo
Morfinismo

Reputation: 5253

Considering the fact that your TaskByKey pretends to filter only a specific task... you can put the following on the onClick event of the button.

var taskKey = widget.datasource.item._key;
var ds = app.datasources.TaskByKey;
ds.query.filters._key._equals = taskKey;
ds.load();
//Then, here you either navigate to a page or open a dialog or open a popup.

The above will work considering that your Tasks datasource and your TaskByKey datasource come from the same model.

Reference: https://developers.google.com/appmaker/scripting/api/client#Query

Upvotes: 1

Related Questions