Reputation: 880
I would like to add a new row to ag grid with one of the columns having a default value. My aim is to make this auto-generated value 1 more than the max number in the column already. (This is assuming that the numbers in the column will be strictly consecutive by one.)
I have taken a look at the ag grid 'Updating Data' page but the issue here is that let's say you click on 'Add Row'. Toyota 1 will appear in the next row - but if you delete that row and click on "Add Row" again, Toyota 2 will appear - despite the fact that there is no longer a Toyota 1 in the column.
I suspect this is because this example does not keep track of the max integer in the column.
How would one be able to click on "Add Row" and have the integer in the column exactly one more than the current max?
Example: Let's say I click on "Add Row" five times.
Let's say I want my 'ColumnA' to be updated with 1 more than the current max. I should see something along the lines of:
[Add Row]
ColumnA ColumnB ColumnC
1
2
3
4
5
Edit:
If ColumnA's current values are
1
3
6
8
17
Then I would like 'Add Row' to create 18 as the next row. And if I delete'17', and then click on 'Add Row, I would like '9' as the next row's value.
Upvotes: 1
Views: 2542
Reputation: 2801
You'll have to find the max id of grid's data. For that, you can use forEachNode((node, index))
onAddRowClick(){
let max = 0
api.forEachNode( function(rowNode, index) {
max < rowNode.myIndex ? max = rowNode.myIndex:;
});
// do your stuff with new index = max + 1
}
Upvotes: 1