Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Interactive Grid with JS - Rows Disappearing - APEX 24.1.2

Fernando A. Medina PegueroSep 3 2024 — edited Sep 3 2024

Hello Everyone. I hope you're doing great.

I have an Interactive Grid with several JS dynamic actions on it. Only one of them is giving me this problem so far.

The task this has is to calculate something based on values of different columns, and it does that flawlessly. The problem comes when I save the data (It does not matter if I use the ‘Save’ Button on the IG or if I invoke it via JS), the row I updated disappears, and if I reload the page, the row appears again (updated).

Here's a video of it:
https://drive.google.com/file/d/1TB1Pvu7NnAU6lnKuSKsouCBr5ke-AGxS/view?usp=sharing

And also, here's my code:

function calcularTotalCarga() {
    var widget = apex.region('pred-ig').widget();
    var grid = widget.interactiveGrid("getViews", "grid");
    var model = grid.model;

    if (!model) {
        // console.error("No se pudo obtener el modelo del Interactive Grid.");
        return;
    }

    setTimeout(function() {
        var selectedRecords = grid.getSelectedRecords();
        if (!selectedRecords || selectedRecords.length === 0) {
            // console.log("No se encontró ningún registro seleccionado.");
            return;
        }

        selectedRecords.forEach(function(record) {
            var idSolicitud = model.getValue(record, "IDSOLICITUD");

            // Verifico si IDSOLICITUD es nulo
            if (idSolicitud === null || idSolicitud === undefined || idSolicitud === "") {
                var totalCarga = 0;

                for (var i = 1; i <= 4; i++) {
                    // Obtener la cantidad y asegurarse de que sea un número válido
                    var cantidadStr = model.getValue(record, "DISTCANTIDAD" + i);
                    var cantidad = parseInt(cantidadStr, 10);
                    if (isNaN(cantidad)) {
                        cantidad = 0; // Si la cantidad no es un número, asignar 0
                    }

                    var denObj = model.getValue(record, "DISTDENOMINACION" + i);

                    if (denObj && denObj.d) {
                        // Asegurarse de que la denominación sea un número válido
                        var denStr = denObj.d.split(' ')[1];
                        var denominacion = parseInt(denStr, 10);
                        if (isNaN(denominacion)) {
                            denominacion = 0; // Si la denominación no es un número, asignar 0
                        }

                        var subtotal = cantidad * denominacion;
                        totalCarga += subtotal;
                        // console.log("D" + i + ": Cantidad:", cantidad, "Denominación:", denominacion, "Subtotal:", subtotal);
                    }
                }

                // Asegurarse de que TOTAL_CARGA se inserte como string
                model.setValue(record, "TOTAL_CARGA", totalCarga.toString());
                // console.log("TOTAL_CARGA actualizado:", totalCarga);

                // Guardo los cambios solo si se ha modificado el registro
                apex.region('pred-ig').widget().interactiveGrid("getActions").invoke("save");
            }
        });
    }, 500);
}


calcularTotalCarga();

Hope you can help me find a solution for this.

Best,

FM.

This post has been answered by Karel Ekema on Sep 3 2024
Jump to Answer
Comments
Post Details
Added on Sep 3 2024
11 comments
155 views