# How can I defer loading data into angular datatable from search function?

I have a web page that allows a user to search for data. I make an API call to the server and retrieve a JSON array back in return. I then (and only then) want to populate the results into a datatable.

However, using fromSource( data ) keeps throwing Invalid JSON errors. I don’t feel I can use fromFnPromise() because I’m not retrieving the data at the time the datatable is rendered. The datatable renders on page load but the search results are loaded at a later time.

I have tried using \$scope.dtInstance.changeData( data ); but that also throws Invalid JSON errors.

Is there a way I can render the datatable on page load and then plug the data in at a later time and force a redraw of the table?

Everything I read points me to using fromFnPromise(), however, because my data comes from a user interaction, I’m not sure how to go about it.

Source: AngularJS