0

I am trying to update a Javascript object value so that I can push it into an new array for filtering, but I then need to reset the object's property value back to its original value for when the user removes the filter (the user can toggle it on and off). I have tried everything I have seen here on stackoverflow and nothing has seemed to work. I have tried:

if (ctrl.dataArray.indexOf(row) === -1) { var rowCopy = JSON.parse(JSON.stringify(row)); row.$$treeLevel = 0; ctrl.dataArray.push(row); row.$$treeLevel = rowCopy.$$treeLevel; } 

I've also tried:

if (ctrl.dataArray.indexOf(row) === -1) { var rowCopy = angular.copy(row); row.$$treeLevel = 0; ctrl.dataArray.push(row); row.$$treeLevel = rowCopy.$$treeLevel; } 

I'm essentially trying to update grid rows to show grids matching specific criteria, then set the grid back to it original state after the filter. I know the dataArray is getting updated with the "originalCopy" value after I am pushing into the array.But how can I keep this from happening?

I have to push the original row so the user can update it and then reset the filter and keep the updated grid cell value for saving.

How can I make my above code work?

6
  • What is the issue with code at Question?CommentedNov 3, 2017 at 0:03
  • 1
    Not sure the cause of your bug - but you might be making this more complex than it needs to be. You could implement filtering for the grid by putting a visible boolean on each row object, setting it to false if the row doesn't pass the filter, then loop through your rows and draw only the ones where visible === trueCommentedNov 3, 2017 at 0:17
  • 1
    classList.toggle('myEffectOrLook')CommentedNov 3, 2017 at 0:25
  • This data is coming from the database, adding a property would be the easiest solution but I'm not sure if that is possible. I can look into that.
    – bschmitty
    CommentedNov 4, 2017 at 0:58
  • @RonRoyston can you describe your solution in more detail
    – bschmitty
    CommentedNov 4, 2017 at 0:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.