0

Merge two tables in HTML and Ninox

Hi there I have to tables for a mail systen in Ninox

One is saving all written ones the other one is saving all incoming emails. 

For a better overview I wanted to merge booth tables in a contact section of a client. 

The idea is that I can see in this list all incomming and outgoing emails as an overview. 

A tried couple of thinks but I am gettin error Messages for email.Datum, email.Betreff and Email.Absender. 

As soon as I am removing a table in 
let combinedEmails := emailSchreiben + emailVerwaltung;

everything works (of course only with one table). My guess is, that there is a problem with merching the tables. Maybe some of you have an idea?

let emailSchreiben := do as server
    (select 'Email Schreiben').{
        Datum: 'Datum + Uhrzeit',
        Betreff: if Betreff then Betreff else "Kein Betreff" end,
        Absender: if Absender.Vorname then Absender.Vorname else "Unbekannt" end,
        Status: "<span style='background-color: green; color: white; padding: 5px 10px; border-radius: 5px;'>Gesendet</span>"
    }
end;

let emailVerwaltung := do as server
    (select 'Email Verwaltung').{
        Datum: 'Datum + Uhrzeit',
        Betreff: if Betreff then Betreff else "Kein Betreff" end,
        Absender: if Absender.Vorname then Absender.Vorname else "Unbekannt" end,
        Status: "<span style='background-color: blue; color: white; padding: 5px 10px; border-radius: 5px;'>Empfangen</span>"
    }
end;

let combinedEmails := emailSchreiben + emailVerwaltung;

html("
<table style='width: 100%; border-collapse: collapse;'>
    <thead>
        <tr>
            <th style='border: 1px solid #ddd; padding: 8px;'>Datum</th>
            <th style='border: 1px solid #ddd; padding: 8px;'>Betreff</th>
            <th style='border: 1px solid #ddd; padding: 8px;'>Absender</th>
            <th style='border: 1px solid #ddd; padding: 8px;'>Status</th>
        </tr>
    </thead>
    <tbody>" +
    for email in combinedEmails do
        "<tr>
            <td style='border: 1px solid #ddd; padding: 8px;'>" + if email.Datum then text(email.Datum) else "Unbekannt" end + "</td>
            <td style='border: 1px solid #ddd; padding: 8px;'>" + email.Betreff + "</td>
            <td style='border: 1px solid #ddd; padding: 8px;'>" + email.Absender + "</td>
            <td style='border: 1px solid #ddd; padding: 8px; text-align: center;'>" + email.Status + "</td>
        </tr>"
    end +
    "</tbody>
</table>
")

9 replies

null
    • Fred
    • 2 wk ago
    • Reported - view

    I think you might need to change:

    let combinedEmails := emailSchreiben + emailVerwaltung;
    

    to

    let combinedEmails := array(emailSchreiben,emailVerwaltung);
    

    When you create the two JSON variables, you are creating an array of data as well. So to merge two arrays you use the array() command. You can't use the + symbol to merge two arrays.

      • Christoph_Hintermuller
      • 2 wk ago
      • Reported - view

       Wow that was easy! Thanks for your help!!!!

      • Fred
      • 2 wk ago
      • Reported - view

      Please mark the post answered when you have a moment.

    • Christoph_Hintermuller
    • 2 wk ago
    • Reported - view

    I have one other question. 
    Finally I added a function customOpenRecords which is showing me the iD and the Table Name from the single records. I double checkt it with an alert. The table name and the ID is right. But however Ninox doesn't open the conected record in a  pop Up window when I am clicking on the datas. 

    My guess is, it has something todo that Ninox first has to open the right table and then the record within the table. Maybe you have an idea?

    let emailSchreiben := do as server
            (select 'Email Schreiben').{
                ID: number(Nr),
                Tabelle: "Email Schreiben",
                Datum: date('Datum + Uhrzeit'),
                Betreff: if Betreff then Betreff else "Kein Betreff" end,
                Absender: if Absender.Vorname then Absender.Vorname else "Unbekannt" end,
                Status: "<span style='background-color: green; color: white; padding: 5px 10px; border-radius: 5px;'>Gesendet</span>"
            }
        end;
    let emailVerwaltung := do as server
            (select 'Email Verwaltung').{
                ID: number(Nr),
                Tabelle: "Email Verwaltung",
                Datum: date('Datum + Uhrzeit'),
                Betreff: if Betreff then Betreff else "Kein Betreff" end,
                Absender: if Absender.Vorname then Absender.Vorname else "Unbekannt" end,
                Status: "<span style='background-color: blue; color: white; padding: 5px 10px; border-radius: 5px;'>Empfangen</span>"
            }
        end;
    let combinedEmails := array(emailSchreiben, emailVerwaltung);
    html("
    <style>
        tr:hover {
            background-color: #f0f8ff;
        }
    </style>
    <table style='width: 100%; border-collapse: collapse;'>
        <thead>
            <tr>
                <th style='border: 1px solid #ddd; padding: 8px;'>Datum</th>
                <th style='border: 1px solid #ddd; padding: 8px;'>Betreff</th>
                <th style='border: 1px solid #ddd; padding: 8px;'>Absender</th>
                <th style='border: 1px solid #ddd; padding: 8px;'>Status</th>
            </tr>
        </thead>
        <tbody>" +
    for email in combinedEmails do
        "<tr class='highlight-row' onclick='customOpenRecord(this)' data-table='" +
        email.Tabelle +
        "' data-id='" +
        email.ID +
        "' style='cursor: pointer;'>
                <td style='border: 1px solid #ddd; padding: 8px;'>" +
        date(email.Datum) +
        "</td>
                <td style='border: 1px solid #ddd; padding: 8px;'>" +
        email.Betreff +
        "</td>
                <td style='border: 1px solid #ddd; padding: 8px;'>" +
        email.Absender +
        "</td>
                <td style='border: 1px solid #ddd; padding: 8px; text-align: center;'>" +
        email.Status +
        "</td>
            </tr>"
    end +
    "</tbody>
    </table>
    <script>
    function customOpenRecord(row) {
        // Hole die Tabelle und Datensatz-ID aus den Attributen
        let tableName = row.getAttribute('data-table');
        let recordId = row.getAttribute('data-id');
    
    
        // Öffne den Datensatz im Popup
        ui.popupRecord(tableName, recordId);
    }
    </script>")
    
      • Fred
      • 2 wk ago
      • Reported - view

      Looking at other posts (1,2) about ui.popupRecord() I see that it needs the nid of the record to work. A nid consists of tableId and recordId, so Ninox knows which record to open. You can get the nid through a select. Which is good since you use select() to get your records.

      So you can add a new key:

      let emailSchreiben := do as server
              (select 'Email Schreiben').{
                  ID: number(Nr),
                  recId: Id,
      
      let emailVerwaltung := do as server
              (select 'Email Verwaltung').{
                  ID: number(Nr)
                  recId: Id,

      Then modify your function:

      ui.popupRecord('recId')
      

      Though you might need to modify it match the html and Ninox coding.

      • Christoph_Hintermuller
      • 2 wk ago
      • Reported - view

       ok that would explain it. But everytime when I try to add recId: Id, Ninox gives me an error and says that the column was not found... That makes no sense to me beacause the nid is created by the system isn't?

      • Fred
      • 2 wk ago
      • Reported - view

      Is Nr the german version of Id? If it is then you can use Nr.

      • Christoph_Hintermuller
      • 2 wk ago
      • Reported - view

       it is. Ok let me try that...

    • Christoph_Hintermuller
    • 2 wk ago
    • Reported - view

    its working!!! Thanks so much! 

Content aside

  • Status Answered
  • 2 wk agoLast active
  • 9Replies
  • 42Views
  • 2 Following