0

Ninox 4 – Custom Component reading linked records makes the form jump on record change. Best practice?

Hi everyone,

I'd like to understand how Custom Components render in Ninox 4 when they read data from linked tables.

Generic setup:

- Table A has N:1 links to Table B and Table C.

- At the top of Table A's form there is a Custom Component (header) that displays values from the linked records, for example an image URL from B (linkB.image_url) and a name from C (linkC.name), together with some fields of the current record.

What happens:

When navigating between records in Table A (up/down arrows), the component disappears for a moment, the whole form shifts up, then the component renders without the linked data, and finally the linked values/images appear and the layout moves again. Using a fixed height on the component container and fixed-size placeholders for images did not prevent the shift.

Workaround that fixed it:

I added Text fields in Table A to store copies of the linked values, filled them with a script, and changed the component to read only fields of the current record. Now the form stays stable and only the images load in place.

Questions:

1. Is it expected that a Custom Component waits for linked records to load before rendering, without reserving its space?

2. Is copying linked values into local fields (denormalising) the recommended practice in Ninox 4, or is there a better approach, e.g. a setting, a loading placeholder, or a more efficient way to read linked records inside a component?

3. Is reading through a relation (e.g. linkB.field or a reverse relation) faster than using select … where inside a component, and does it affect rendering?

 

Thanks in advance for any insights!

10 Antworten

null
    • Customer Support Ninox
    • uwe_groegor
    • vor 8 Tagen
    • Gemeldet - anzeigen

    Hallo  
    Als Hinweis:
    Das ist das deutsche Forum. Bitte erstelle deine Beiträge hier auf deutsch.
    Wenn du auf english schreiben willst, kannst du dafür das englische Forum nutzen.

    Zu deiner Anfrage:
    Ich habe deine Anforderung in einer BeispielApp auf einfache Art nachgebaut.
    Ich kann das von dir beschriebene Verhalten bei Linkfeldern bei 'benutzerdefinierten Komponenten' nicht als grundsätzlich nachvollziehen.
    Die 'benutzerdefinierte Komponente' löst ja die html-Funktion, welche in Ninox3 in Berechnungsfeldern genutzt wurde ab.
    In wieweit in 'benutzerdefinierten Komponenten' umfangreiches Scripting betrieben wird liegt ja bei dem Anwender selbst.
    Meine Tests haben ergeben, dass bei einfachen html-Script der Formularaufbau beim Wechsel zwischen Records grundsätzlich keine Verzögerung mit sich bringt.
    Der Inhalt des Feldes 'benutzerdefinierte Komponente' wird vollständig und sofort angezeigt.

    Ich füge ein Screenvideo bei, welches meinen Nachbau in einfacher Form zeigt und das Script, welches ich für die 'benutzerdefinierte Komponente' verwendet habe.

    Script verwendete 'benutzerdefinierte Komponente'

    function Row(label: string, value: any) do
        <div class="flex flex-col">
            <span class="text-xs text-default-500">
                { label }
            </span>
            <span class="text-lg font-semibold">
                { value }
            </span>
        </div>
    end;
    <div class="flex flex-col gap-3 p-4 rounded-lg bg-content1 text-foreground shadow">
        <Row label="FieldTblA:" value={ name }/>
        <Row label="FieldTblB:" value={ tableb.company }/>
        <Row label="FieldTblC:" value={ tablec.ort }/>
    </div>
      • Rafael_Sanchis
      • vor 8 Tagen
      • Gemeldet - anzeigen

       

      Hello Uwe,

      Thank you very much for taking the time to recreate it and for the recording – very helpful.

      I agree with your result: with simple text fields from linked tables, the component renders immediately. I tested it again and the difference in my case came from two things your example doesn't include:

      1. Images: my header showed team logos with <img src="…"> using shareFile() URLs from the linked table. The browser loads the images after the component is drawn, and without fixed sizes the layout moved.

      2. Heavier scripting: several select … where queries and aggregations (leader, totals, form) on other tables inside the component.

      After simplifying the headers to text only (no images, values pre-calculated by a button and stored in fields), the form no longer jumps. So, as you say, it depends on how much scripting is put inside the component.

      Thanks also for the function Row(…) pattern and the bg-content1 / text-foreground classes – I'll use them to simplify my components.

       

      Best regards,

      Rafael

      • Rafael_Sanchis
      • vor 8 Tagen
      • Gemeldet - anzeigen

       

      Simple example

      function Row(label: string, value: any) do

      <div class="flex flex-col">

      <span class="text-xs text-default-500">

      { label }

      </span>

      <span class="text-lg font-semibold">

      { value }

      </span>

      </div>

      end;

      <div

      class="flex items-center gap-6 p-4 rounded-lg bg-content1 text-foreground shadow"

      >

      <div style="width:56px;height:56px;flex-shrink:0">

      { if text(logo_link) != "" then

      <img src={ text(logo_link) } style="width:56px;height:56px;object-fit:contain"/>

      end }

      </div>

      <Row label="Company" value={ company }/>

      <Row label="Projects" value={ cnt(table_a) }/>

      <Row label="Cities" value={ join(unique(table_a.table_c.ort), ", ") }/>

      </div>

      The script en header Table B

      • Rafael_Sanchis
      • vor 8 Tagen
      • Gemeldet - anzeigen

      What I observed:

      - In Table C, the custom component header contains only text: the city name, the number of projects and the list of companies. These values are read through the reverse relation (cnt(table_a), unique(table_a.tableb.company)).

      - When switching records (for example, from Paris to Caracas), the header disappears for a moment and a loading spinner appears. The rest of the form moves up. Then the header renders and pushes the form down again.

      - The related-records subtable (Table A) also appears with a delay: first empty, then filled.

      - Table B shows the same behaviour, and its header also uses the reverse relation.

      So the shift happens even without images. My conclusion, which I'd like you to confirm, is:

      - Reading N:1 links "upwards" (tableb.company, tablec.ort), as in your example, renders immediately.

      - Reading 1:N reverse relations or using select inside the component makes the component wait until the related records are loaded. Because its space is not reserved in the meantime, the form shifts.

      Your example only uses N:1 links, which would explain why you didn't see the delay. I will add your exact script to Table A and record it next to the Table C header to compare both cases directly.

      Is this the expected behaviour for reverse relations? And is there a recommended way to avoid the shift, such as reserving the component height, or pre-calculating these values into fields of the record?

       

      Best regards,

      Rafael

    • Customer Support Ninox
    • uwe_groegor
    • vor 7 Tagen
    • Gemeldet - anzeigen

     
     

    Ich habe es jetzt auch mit einem Logo nachgebaut.
    Ich sehe keine grossen unterschiede.
    Bei der Anzeige der 1:n Verknüpfungen gibt es immer ein kurzes Delay bis sich alle Datensätze aufgebaut haben.
    Man muss beobachten, wie es sich bei einer sehr grossen Anzahl von Datensätzen verhält.
    Das Verschieben der Elemente whärend des Formularaufbaus kann ich nicht nachvollziehen.
    Der Aufbau der 'benutzerdefinierten Kompomnente' ist nach meinen Test auch abhängig wie das Logo erzeugt wird.
    Wenn man die sharefile()-Funktion innerhalb des Scripts anwendet dauert es länger, als bei bereits gespeicherter Url des Files.
    Grundsätzlich hat man aufgrund des Bildes im ersten Durchgang immer eine zeitliche Verzögerung, die sich aber bei erneutem Durchlauf erledigt, da dann scheinbar der Browsercache greift.

    Anbei das Script der verwendeten 'benutzerdefinierten Komponente' und das Screenvideo der überarbeiteten App.

    function Row(label: string, value: any) do
        <div class="flex flex-col">
            <span class="text-xs text-default-500">
                { label }
            </span>
            <span class="text-lg font-semibold">
                { value }
            </span>
        </div>
    end;
    <div
        class="flex flex-row items-center gap-4 p-4 rounded-lg bg-content1 text-foreground shadow"
    >
        <img src={ shareurl } alt="Bild" class="w-16 h-16 rounded-lg object-cover"/>
        <div class="flex flex-col gap-3">
            <Row label="FieldTblA:" value={ name }/>
            <Row label="FieldTblB:" value={ tableb.company }/>
            <Row label="FieldTblC:" value={ tablec.ort }/>
        </div>
    </div>
    
      • Rafael_Sanchis
      • vor 5 Tagen
      • Gemeldet - anzeigen

       

      Ninox 4 custom components – 4 lessons learned (performance & images)

      1. Avoid do as server in interactive components

      Every state change (a click, a selection, typing) re-evaluates the whole component, and that includes the do as server block. That means a round trip to the server on every click. In my case selecting a row in a list took about 3 seconds. After I removed do as server and ran the same queries locally, the response was instant, because Ninox already has the records in the browser.

      Keep do as server for heavy calculations that run once or from a button, not for components with state.

      2. External images are blocked

      An <img> pointing to an external site (e.g. a logo CDN) shows as a broken image inside custom components, even when the URL works fine in the browser. Adding referrerpolicy="no-referrer" doesn't help. These sources do work:

      links generated with shareFile() (files stored in Ninox)

      Base64 data URIs (data:image/png;base64,...)

      3. shareFile() must run from a button

      shareFile() can't be used in a formula field. Run it from a button and store the result in a text field:

      for t in select '02_teams' do

       if t.logo != null then

        t.(logo_link := shareFile(t.logo))

       end

      end

      Then the component just reads logo_link.

      4. Query each table once, then filter in memory

      Instead of running a select per row (e.g. to look up each team's logo), load the table once and filter the array:

      let tms := select '02_teams';

      ...

      hl: text(first(tms[text(team_name) = hn]).logo_link)

      This took me from 37 queries down to 2 for an 18-match list.

    • Customer Support Ninox
    • uwe_groegor
    • vor 16 Stunden
    • Gemeldet - anzeigen

    Den Fehler bei der Verwendung von externen Links habe ich an die Entwickler weiter gemeldet.

    Der Aussage, dass shareFile() nicht in der custom Component verwendet werden kann muss ich widersprechen.
    Das nachfolgende Script funktioniert bei mir.

    function Row(label: string, value: any) do
        <div class="flex flex-col">
            <span class="text-xs text-default-500">
                { label }
            </span>
            <span class="text-lg font-semibold">
                { value }
            </span>
        </div>
    end;
    <div
        class="flex flex-row items-center gap-4 p-4 rounded-lg bg-content1 text-foreground shadow"
    >
        <img src={ shareFile(filetblb) } alt="Bild" class="w-16 h-16 rounded-lg object-cover"/>
        <div class="flex flex-col gap-3">
            <Row label="FieldTblB:" value={ company }/>
        </div>
    </div>
    

    Es ist aus meiner Sicht jedoch sinnvoller den von Ninox erzeugten Sharelink dauerhaft in einem Feld abzulegen und in der 'custom component' auf diesen zuzugreifen.

    Das direkte Aktualisieren der custom component nach Eingabe/Änderung von Feldern aussserhalb der 'custom component' kann ich nicht bestätigen.
    Da wird es wahrscheinlich wieder auf das verwendete Script innerhalb der 'custom component' ankommen.

    'custom component' sind vereinfacht gesagt nichts anderes als 'Logik Felder', die einer Renderfunktion inne haben.
    Sie ersetzen die in Ninox3 benutzte Funktion html(), die zum Rendern in Formelfeldern benutzt wurde.
    Damit einher gehend gelten für 'custom components' die gleichen scripting Regeln bei Verwendung von Ninox Scriptcode, wie sie in den Formelfeldern angewendet wurden.
    (select nur einmalig pro Tabelle etc.)

      • Rafael_Sanchis
      • vor 12 Stunden
      • Gemeldet - anzeigen

       

      Hi UGE, thanks for the feedback and the example. You’re right: shareFile() can be called directly inside a custom component, and my guide was too absolute on that point. I’ll correct it.

      We do agree on the recommendation, though: generate the share link once (with a button or a trigger), store it in a text field, and have the component read only that field. The component stays lighter and the link stays stable.

      For small images such as logos and avatars, I now mostly use Base64 stored in a text field, which removes the need for a share link altogether. The images also render instantly and don’t depend on links that can expire.

      I also agree with your other points. Whether the component refreshes when fields outside it change depends on the script inside the component. And custom components behave like formula fields with a render function, replacing html() from Ninox 3, so the same scripting rules apply: one select per table and filtering in memory.

      Thanks again!

      • Customer Support Ninox
      • uwe_groegor
      • vor 4 Stunden
      • Gemeldet - anzeigen

       
      Eine Anmerkung zu speichern von Base64 in Textfeldern.
      Ich würde davon dringen abraten.
      Aus Ninox3 wissen wir durch zahlreich untersuchte Datenbanken von Kunden, dass dieses Vorgehen zu einem extremen Anstieg an verbrauchten Speicherplatz führen kann.
      Besser ist es extrem lange Strings als Textfile zu speichern und diese in einem Dateifeld abzulegen,
      Bei Bedarf kann man sie dann per Script in eine Variable laden und damit weiterarbeiten.

      #####
      A note on storing Base64 data in text fields:
      I would strongly advise against this.
      Based on our experience at Ninox3—having examined numerous customer databases—we know that this approach can lead to an extreme increase in storage consumption.
      It is better to save extremely long strings as text files and store them in a file field.
      If needed, you can then load them into a variable via a script and work with them further.

      • Rafael_Sanchis
      • vor 3 Stunden
      • Gemeldet - anzeigen

       

      Thanks for the heads-up. I ran a test: generating the Base64 on the fly with loadFileAsBase64URL() works in Ninox 4 custom components, but it takes about 0.3 s per image (around 10 s for 36 images), so it's not practical for lists or charts. In my case there are only 36 images at 64 px (under 200 KB in total), so I'm keeping the Base64 in a text field for these components. I agree I wouldn't recommend it for large tables or for images that haven't been resized.

Content aside

  • vor 3 StundenZuletzt aktiv
  • 10Antworten
  • 46Ansichten
  • 2 Folge bereits