Page 1 of 1

lookup field sum

Posted: 2023-10-25 11:26
by crnjak
is anybody know how to sum in tableviewev lookup fields.
picture in attach
Untitled.jpg
Untitled.jpg (43.37 KiB) Viewed 4849 times

Re: lookup field sum

Posted: 2023-10-25 12:46
by jsetzer
If these are lookup fields, as you say, there is only primary keys (IDs) inside the database table. I don't think building a sum would give any useful information.

Just in case those fields are autofill-lookup fields, having numeric display values, there is still only primary keys in the database for them.

Maybe I'm wrong, but I don't think there is a built in functionality for loading related values from the master table and summing them up.

Should work with javascript.

Re: lookup field sum

Posted: 2023-10-26 07:22
by crnjak
Jan can you give me some example for this?

Re: lookup field sum

Posted: 2023-10-26 12:25
by jsetzer
(Additional) Custom Row in <tfoot>.

Code: Select all

// file: hooks/TABLENAME-tv.js
jQuery(document).ready(function () {
    const table = jQuery(`table.table[data-tablename='${AppGini.currentTableName()}']:eq(0)`);
    const tfoot = table.children("tfoot:eq(0)");
    const tr = jQuery("<tr/>").addClass("info").prependTo(tfoot);

    table.find("thead:eq(0) > tr:eq(0) > th").each(function (i, e) {
        const th = jQuery("<th/>")
            .appendTo(tr)
            .addClass("text-nowrap")
            .append(i > 0 ? `cell #${i}` : '')
            .append("<br/>")
            .append(jQuery("<code/>").append(i > 0 ? `${jQuery(e)[0].classList[0]}` : ''));
    });

});
chrome_V2vfz36mXi.png
chrome_V2vfz36mXi.png (228.63 KiB) Viewed 4784 times

You can identify the column by index (i-variable) or by evaluating class-name of cell, which should be in format TABLENAME-COLUMN.

chrome_7bZaiaAaD3.png
chrome_7bZaiaAaD3.png (33.78 KiB) Viewed 4784 times


For pupulating the cell-contents, for example use jQuery.getJSON(...) and fetch sums from your server using your own API or 3rd party API.

This is just an example, showing the first steps. Completing it including AJAX, serverside script, formatting, error-handling etc. would take too much time now.