Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to create a join field? #8

Open
kevin8181 opened this issue Mar 19, 2022 · 4 comments
Open

how to create a join field? #8

kevin8181 opened this issue Mar 19, 2022 · 4 comments

Comments

@kevin8181
Copy link
Contributor

@glutamate how do I make the color field show options for join fields? like if someone had a table of event types, and each one had a color field, and the events are children of the event types

@glutamate
Copy link
Contributor

glutamate commented Mar 21, 2022

Exactly this scenario done in the new gantt chart @kevin8181

First, make the array of field names the user can choose the color field from. I start with an array of all the color fields on the associated table: https://github.com/saltcorn/svelte-gantt/blob/c70268d16e0043ec8bf357720cafea732b6a1f95/index.js#L35-L37

then loop through the key fields: https://github.com/saltcorn/svelte-gantt/blob/c70268d16e0043ec8bf357720cafea732b6a1f95/index.js#L38-L39

get the parent table, its fields, and append all color fields to the array of options, a string with a dot separating the key field from the field on the joined table: https://github.com/saltcorn/svelte-gantt/blob/c70268d16e0043ec8bf357720cafea732b6a1f95/index.js#L44-L46

cfg form field as normal: https://github.com/saltcorn/svelte-gantt/blob/c70268d16e0043ec8bf357720cafea732b6a1f95/index.js#L138-L145

in the run method, figure out if it is a join field i.e. has a dot: https://github.com/saltcorn/svelte-gantt/blob/c70268d16e0043ec8bf357720cafea732b6a1f95/index.js#L230

if yes, add a join field to the joinFields argument to getJoinedRows: https://github.com/saltcorn/svelte-gantt/blob/c70268d16e0043ec8bf357720cafea732b6a1f95/index.js#L231-L234

key in joinFields object is the variable name in the fetched rows, ref is the key field name and target is the name of the field on the join table which will hold the data.

used here https://github.com/saltcorn/svelte-gantt/blob/c70268d16e0043ec8bf357720cafea732b6a1f95/index.js#L238

The use of the color variable here was very idiosyncratic according to the underlying library, hopefully you don't have to create the CSS classes as I do. to retrieve the color you still have to keep track of its name though like this: https://github.com/saltcorn/svelte-gantt/blob/c70268d16e0043ec8bf357720cafea732b6a1f95/index.js#L292-L293

@glutamate
Copy link
Contributor

for more examples of getJoinedRows and its joinFields argument, see this test file https://github.com/saltcorn/saltcorn/blob/master/packages/saltcorn-data/tests/table.test.ts

@kevin8181
Copy link
Contributor Author

kevin8181 commented Mar 22, 2022

maybe there should be a function for this? like pass a table, array of data types, parent depth, child depth, and get the values back? seems like something used often enough to make a standardized system

either way I'll give this a try

@Lulubel
Copy link

Lulubel commented Sep 5, 2022

Hello. I agree Full calendar should use the joined fields. I have a table "_actions" with all the informations about a project, like the title ; and a table "_dates" with a join field "action" on _actions (relation type: one action to many dates). I use the view Calendar on the _dates table. I would like the title show on the calendar but the extension only propose the _dates fields for "Event title field". (Sorry for my english). Thanks for your answer. Aurélie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants