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!

Adding New Rows with Default Values in Interactive Grid

Hi!

I'm working on an Oracle APEX application and need to add new rows to an Interactive Grid with default values derived from certain page items. I've created a custom button on the Interactive Grid toolbar that should add a new row with specific values from the page items. However, the new row is being created empty.

Here is the code I'm using to define the button action in the Interactive Grid initialization function:

function(config) {
    let $ = apex.jQuery,
        toolbarData = $.apex.interactiveGrid.copyDefaultToolbar(),
        toolbarGroup = toolbarData.toolbarFind("actions3"); // Find the actions group

    if (toolbarGroup) {
        toolbarGroup.controls.push({
            type: "BUTTON",
            id: "add-row-values-button",
            label: "Añadir",
            icon: "fa fa-plus", // Trash icon
            iconBeforeLabel: true,
            action: "add-row-values" // Action to delete selected rows
        });
    }

    // Define the new actions
    config.initActions = function(actions) {
        // Add action for adding a row with specific values
        actions.add({
            name: "add-row-values",
            label: "Añadir",
            action: function(event, focusElement) {
                var region = apex.region("BOLSA_IG"),
                    grid = region.widget().interactiveGrid("getViews", "grid"),
                    model = grid.model,
                    view = grid.view,
                    newRecord = {};

                // Define the values for the new record
                newRecord.COLUMN1= $v("P17_COLUMN1");
                newRecord.COLUMN2= $v("P17_COLUMN2");
                newRecord.COLUMN3= $v("P17_COLUMN3");
                newRecord.COLUMN4= $v("P17_COLUMN4");

                // Insert the new record into the grid model
                model.insertNewRecord(newRecord);
            }
        });
    };

    config.toolbarData = toolbarData;
    return config;
}

While the new row is created in the Interactive Grid, the fields remain empty. The row is added, but none of the specified values are populated. I have verified that the page items (P17_COLUMN1, P17_COLUMN2, P17_COLUMN3, P17_COLUMN4) contain the correct values.

Has anyone encountered a similar issue or have any suggestions on how to fix this?

Thanks in advance for your help!

This post has been answered by Karel Ekema on Jul 23 2024
Jump to Answer
Comments
Post Details
Added on Jul 23 2024
2 comments
2,837 views