Forum Stats

  • 3,838,704 Users
  • 2,262,394 Discussions
  • 7,900,739 Comments

Discussions

Auto increment the IG column value on add row button click.

ApexLearn
ApexLearn Member Posts: 267 Blue Ribbon
edited Jun 30, 2022 5:59AM in APEX Discussions

Hi,


am using oracle apex 19.2 version.

How to increment the Interactive grid column value when add row button click.

As shown in the above screenshot, need to get the sequence automatically when click on Addrow button.

I tried with the below link but the value is increment for click on the grid but should work on addrow button click only.

Auto increment number on click add row button in interactive grid Oracle APEX - Ontoor Blogs (ontoorsolutions.com)


Kindly advice to get the auto increment value in IG column.


Thanks in advance.

Best Answer

  • Hamza Al-abbasi
    Hamza Al-abbasi Member Posts: 596 Gold Trophy

    In case of row is adding from first, then what could be change for sequence variable.

    The Add Row button invokes the built-in action "selection-add-row". This action will add row from the current row selection in the IG, so it will make a wrong sequence. There is another action to add from the first called "row-add-row" you can invoke it as following :

    apex.region("[IG_STATIC_ID]").call('getActions').invoke('row-add-row');
    

Answers

  • Hamza Al-abbasi
    Hamza Al-abbasi Member Posts: 596 Gold Trophy
    edited Jun 30, 2022 9:10AM

    Hello ApexLearn,

    First you need to add custom action to add record to the end of the IG. In IG Attribute Tab => JavaScript Initialization Code :

    function(config) {
        config.initActions = function(actions) {
            actions.add({
                name: "add-row-to-last",
                action: function() {
                    var row$,
                        region = apex.region("[IG_STATIC_ID]"),
                        view = region.call("getCurrentView");
                    
                    if (view.internalIdentifier === "grid") {
                        row$ = region.widget().find(".a-GV-row").last();
                        view.view$.grid("setSelection", row$);
                        region.call("getActions").invoke("selection-add-row");
                    }
                }
            });
        };
        
        return config;
    }
    

    Now, create Row Initialization [Interactive Grid] DA, in True add action "Execute JavaScript Code" :

    var view = apex.region("[IG_STATIC_ID]").call('getCurrentView'),
        model = this.data.model,
        record = this.data.record,
        curSeq = model.getRecordValue(view.getActiveRecordId(), "[SEQUENCE_COLUMN]"),
        seq = model.getTotalRecords() === 1 ? 0 : model.getRecordValue(model.getRecordId(model.recordAt(model.getTotalRecords() - 2)), "[SEQUENCE_COLUMN]");
    
    if(curSeq === ""){
        seq = parseInt(seq) + 1;
        model.setValue(record, "[SEQUENCE_COLUMN]", seq.toString());
    }
    

    Create another button to call the action above :

    apex.region("[IG_STATIC_ID]").call('getActions').invoke('add-row-to-last')
    
  • ApexLearn
    ApexLearn Member Posts: 267 Blue Ribbon

    Thank you @Hamza Al-abbasi , Its working as expected.

    In case of row is adding from first, then what could be change for sequence variable.

    var view = apex.region("[IG_STATIC_ID]").call('getCurrentView'),
        model = this.data.model,
        record = this.data.record,
        curSeq = model.getRecordValue(view.getActiveRecordId(), "[SEQUENCE_COLUMN]"),
        seq = model.getTotalRecords() === 1 ? 0 : model.getRecordValue(model.getRecordId(model.recordAt(model.getTotalRecords() - 2)), "[SEQUENCE_COLUMN]");
    
    if(curSeq === ""){
        seq = parseInt(seq) + 1;
        model.setValue(record, "[SEQUENCE_COLUMN]", seq.toString());
    }
    


  • Hamza Al-abbasi
    Hamza Al-abbasi Member Posts: 596 Gold Trophy

    In case of row is adding from first, then what could be change for sequence variable.

    The Add Row button invokes the built-in action "selection-add-row". This action will add row from the current row selection in the IG, so it will make a wrong sequence. There is another action to add from the first called "row-add-row" you can invoke it as following :

    apex.region("[IG_STATIC_ID]").call('getActions').invoke('row-add-row');
    
  • ApexLearn
    ApexLearn Member Posts: 267 Blue Ribbon

    Can't we achieve the sequence increment if the row add from first.

  • Hamza Al-abbasi
    Hamza Al-abbasi Member Posts: 596 Gold Trophy