Get data from other tables with custom widget in javascript

Hello, I made a custom widget which displays the current selected table in a HTML page. The function I’m using is:

<script src="https://docs.getgrist.com/grist-plugin-api.js"></script>
grist.onRecords(function (records) { ... });

Everything works perfectly.
But if I need to retrieve data from some other table how do I achieve that? Is this possible and what function should I use?

Hello,

It’s possible by using fetchTable (which requires full access to document). You have an example in the “Inspect API” custom widget.

perfect. I tried it and it works (obviously). thx

oops, just one more thing.
if I need to update a field of a specific record of another table what function should I use?

1 Like

it doesn´t allow fetching data from another DOCUMENT however, does it?

@Alfredo_Ardito

if I need to update a field of a specific record of another table what function should I use?

applyUserActions. You have some examples in grist-widget repository.

@Rogerio_Penna
Not that I know. I didn’t ever do this, so I don’t know whether/how it would be possible.

is there a way to return not all the table but with a filter ?

It’s a good question, that I thought I’d ask once I’d have finished my current tasks…

1 Like

Good question too. Obviously filtering means sorting ascending and descending and with a WHERE Clause. Things would a lot easier if we could use SQL statements to query data.

Seems there should be hope on that point: add an endpoint for doing SQL selects by paulfitz · Pull Request #641 · gristlabs/grist-core · GitHub