lookup field sum

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
User avatar
crnjak
Veteran Member
Posts: 37
Joined: 2021-12-29 20:25

lookup field sum

Post by crnjak » 2023-10-25 11:26

is anybody know how to sum in tableviewev lookup fields.
picture in attach
Untitled.jpg
Untitled.jpg (43.37 KiB) Viewed 2712 times

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1817
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: lookup field sum

Post by jsetzer » 2023-10-25 12:46

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.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
crnjak
Veteran Member
Posts: 37
Joined: 2021-12-29 20:25

Re: lookup field sum

Post by crnjak » 2023-10-26 07:22

Jan can you give me some example for this?

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1817
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: lookup field sum

Post by jsetzer » 2023-10-26 12:25

(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 2647 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 2647 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.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply