Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Sequential Numbering Subform Grid Rows Topic is solved

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
treed
Posts: 205
Joined: Mon May 18, 2020 12:02 am
Been thanked: 2 times
Contact:

Sequential Numbering Subform Grid Rows

Unread post by treed »

With a grid subform is there a way to populate new rows with a sequential number starting from 1 as they are added? Or if it would be easier, set the value after a selection is made?
steven
Posts: 369
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 52 times
Been thanked: 52 times

Re: Sequential Numbering Subform Grid Rows

Unread post by steven »

Hi treed,

Add this event to your subform...
afterinsertrow.PNG

And put this js on the Form...

item_sf = subform name
seq_id = id for subform autoid

Code: Select all

function addAuto(){
    
    var a = nuSubformObject('item_sf').rows.length;
    var i = '#item_sf' + nuPad3(nuSubformObject('item_sf').rows.length - 1) + 'seq_id';
    
    $(i).val(a).addClass('nuEdited');
    
}

Steven
You do not have the required permissions to view the files attached to this post.
A short post is a good post.
treed
Posts: 205
Joined: Mon May 18, 2020 12:02 am
Been thanked: 2 times
Contact:

Re: Sequential Numbering Subform Grid Rows

Unread post by treed »

Thanks Steven, Once I figured out that the subform name was the subform object name on the main form and not the subform itself, this code works.

However the way it works is that the first row is not numbered and the next row to be inserted is given the correct number. What I'd like to do is either set the value to 1 for the first row or just number the current row, which ever is easier. Any ideas?
treed
Posts: 205
Joined: Mon May 18, 2020 12:02 am
Been thanked: 2 times
Contact:

Re: Sequential Numbering Subform Grid Rows

Unread post by treed »

Ah figured it out. This now numbers the edited row.

Code: Select all

    var a = nuSubformObject('BuildPac').rows.length - 1;
     var i = '#BuildPac' + nuPad3(nuSubformObject('BuildPac').rows.length - 2) + 'OrdPacBoxNumb';
    $(i).val(a).addClass('nuEdited');
Post Reply