Add multiple rows to a dataview using row-add

Is there a way to add multiple rows to a dataview using row-add or some other widget? The JSON editor in the row-add widget allows you to add a single row. I tried to make it into an array but that did not work. I looked at using the dataview-condition described here and some how using iteration call a separate event that has a row-add widget but the data would need to come from somewhere other than the source dataview. It appears the “Expression” uses data found in the source dataview? This is for an unusual use case so I’m not sure its possible out of the box.

DOES NOT WORK

WORKS(for single entry)

dataview-condition
image

Can you clarify what you’re trying to do?

I’ll try. Its a bit convoluted. I am working on a product configurator. I need for the end user to be able to add, remove and clear part numbers in a grid. The part numbers are returned ,on the fly, from a function call using the rest-erp widget. I created dataviews similar to the Trans view to hold/bind to the grids. The grid data is kept in sync with the text boxes, that are tilde separated values, with a grid change event. The text boxes values are actually what is used during the rules portion of the configurator but I need a way to add/remove/clear the text boxes so I used datagrids. It actually works well. The problem comes in when the user has to reenter a previous configuration the data in the grid is gone since its not backed by a service call or BAQ. So what I did is after the page “is loaded” event I am calling a row-add to fill the dataview/grid with what is in the corresponding text boxes. This works if there is only one item. If there are more I need to be able to add those also.

Working example
screenCast

dataview

So, maybe this will work for you; it’s kind of a loop, if you will.

Create an event to kick it off; I used a button click and set the condition widget to check to see if your index is undefined.

If it is, set it to zero, then call your event that adds a row, otherwise, just go to the add row event.

If it’s false, check to make sure you’re not at the end of the DataView you’re iterating through, then proceed to the add row event.

In the add row event, set the index of the DataView you want to work with.

Add your row.

Index++

Aaaaaaaaaaaaaand magic!

AddRow

** GIF clarification–it’s not removing them from the bottom grid to add to the top; the screen is just growing down as I add new rows to the top grid. :+1:t2:

2 Likes

I’m going to study that a bit. BTW where did you set the ‘%Avail.count%’?

Avail is the name of my DataView.
So, if you want the count of the records in any particular DV, then do ‘%YourDataView.count%’

I was able to accomplish my goal with your help. I load the grids by calling an event on the page loaded event. That event sets a counter to be the total number of tilde separated items in the first text box , of each grid, then calls another event that checks the counter to see if it is zero if not it does a row-add ,accessing the item by the index of the counter, then does a row-update to decrement the counter then calls itself(recursion) until the condition is false. I then do a row-update to reset the counter for the next grid and call the event to kick it off. I even added a refresh button on the grid to manually reload although you can’t see it refresh when I click the refresh button below.

screenCast2

Set the initial counter for the first grid

"#_trans.dataView('Page1').viewData.map(p => p.txtEmergencyStopPartNumber).toString().split('~').length_#"

Check if all rows added
image

#_trans.dataView('TransView').viewData.map(p => +p.ViewIndex)_#  > 0 && "{Page1.txtEmergencyStopPartNumber}" !== ''

If not add row
image

{
	"KeySwitch": "#_trans.dataView('Page1').viewData.map(p => p.txtEmergencyStopPartNumber).toString().split('~').reverse()[trans.dataView('TransView').viewData.map(p => +p.ViewIndex) -1]_#",
	"Halo": "#_trans.dataView('Page1').viewData.map(p => p.txtEmergencyStopHaloPartNumber).toString().split('~').reverse()[trans.dataView('TransView').viewData.map(p => +p.ViewIndex) -1]_#"
}

Decrement counter
image

2 Likes