I have a scrip that iterates through a series of rows in a table and updates pricing based upon a few modifiers. It can take awhile to iterate through every row, so I was wondering if there was a way to only process the rows that have changed… is there a way to check for this in my each loop?
Here’s the loop code…
var quoteLines = skuid.model.getModel('QuoteLineList');<br>if (quoteLines.data.length > 0) {<br> $.each(quoteLines.data, function (i, row){ <br> // do stuff<br> }<br>}
Try this:
var quoteLines = skuid.model.getModel('QuoteLineList');<br>if(quoteLines.data.length){<br>$.each(quoteLines.data, function(i, row){<br>// only proceed if this row has changes by checking the changes obj on the model<br>// (quite elegant if I may say so) <br>if(quoteLines.changes[row.Id]){ <br>//do stuff <br>}<br>}<br>}
The supported way to check this is to use model.isRowChanged(row), like this:
var quoteLines = skuid.model.getModel('QuoteLineList');<br />var quotes = quoteLines.getRows();<br />if (quotes.length > 0) {<br /> $.each(quotes, function (i, row){ <br /> // Only proceed if the row has unsaved changes<br /> if (quoteLines.isRowChanged(row)) {<br /> // Do Stuff<br /> }<br /> }<br />}