Skip to main content

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 &gt; 0) {<br>&nbsp;$.each(quoteLines.data, function (i, row){ &nbsp;<br>&nbsp; // do stuff<br>&nbsp;}<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)&nbsp;<br>if(quoteLines.changes[row.Id]){&nbsp;<br>//do stuff&nbsp;<br>}<br>}<br>}

The supported way to check this is to use model.isRowChanged(row), like this:


var quoteLines = skuid&#46;model&#46;getModel('QuoteLineList');<br />var quotes = quoteLines&#46;getRows();<br />if (quotes&#46;length &gt; 0) {<br />&nbsp; &nbsp;$&#46;each(quotes, function (i, row){ &nbsp;<br />&nbsp; &nbsp; &nbsp; &#47;&#47; Only proceed if the row has unsaved changes<br />&nbsp; &nbsp; &nbsp; if (quoteLines&#46;isRowChanged(row)) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#47;&#47; Do Stuff<br />&nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp;}<br />}

Awesome, thanks guys!