angularjs smart table st-safe-src attribute

user2428697 picture user2428697 · Jun 13, 2015 · Viewed 10.1k times · Source

I have gone through this link http://lorenzofox3.github.io/smart-table-website/. But i have not got the use case of "st-safe-src". when we need to use this attribute.

Answer

Nicolas Charpentier picture Nicolas Charpentier · Jun 16, 2015

I believe this explanation could help you with st-safe-src :

1) You have a displayed collection (ie the repeater) which will be the result of sort, filter, slice operations on a base collection.

2) When initialised smart-table create a copy of the provided st-table collection as its base collection. So the sort,filter,slice are based on the original asset. When calling with ajax, you don't have the dataset at initialisation time so that the base copy is actually wrong. As a side node, I would rather fetch the data when resolving the controller dependencies (ie the resolve in the route) it will ease your unit tests

3) When using the st-safe-src you explicitly tells smart-table to watch and update its base collection ie the one it uses as the reference when sorting, filtering and slicing.

So basically the st-table is the displayed collection (the result) and st-safe-src is the base collection (the original dataset).

So if you set both to the same collection, the latest will be watched and will change the first one, which will trigger the watch...which will update the displayed one....etc.


Reference : https://github.com/lorenzofox3/Smart-Table/issues/156#issuecomment-54242437