Real-time update of the table with data coming from websocket using angularjs

I need to update a table in real time with data coming from a web socket.

What am I doing now, every time I get data on the socket, I add it to the string and create a two-dimensional array that is used to display the table using ng-repeat.

Performance using this approach is rather slow. In addition, this approach assumes that I receive the message in sequence, however I do not receive data in the correct sequence.

Would it be better to format the data as html or json and send it via a web socket or is it better to send the original data?

What would be the best way to do this?

+4
source share
1 answer

If you recreate a two-dimensional array from this line each time, a faster way is to simply direct the new data to the array.

Sending HTML data is not the way to go, but formatting the data as JSON on the server will almost certainly help speed up the work on the client side. Sending small pieces of data and then adding them to your array on the client, and then re-sorting the data (if necessary) is likely to be faster.

Another option would be to use something like the Underscore.js throttle function to limit the number of times you call the digest loop in AngularJS. You can also capture just throttle if you don't want to include all the underlines in your project.

0
source

Source: https://habr.com/ru/post/1440450/


All Articles