Pass datatables to webworker.

Pass datatables to webworker.

pmengopmengo Posts: 74Questions: 37Answers: 2

I have a problem to use datatables instance inside a web worker. How can i pass raw object instead of type API ?
if i use the _API resulting from the instance i get 'Converting circular structure to JSON' Error

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    You will not be able to do that. The problem that you are seeing is because web workers make copies of what you pass them by serialization. Functions inside an object generate that error (I learned the hard way) when you attempt to serialize them.

    https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers

  • pmengopmengo Posts: 74Questions: 37Answers: 2

    i know... but must be a way to do it

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    Use the toArray() method to convert from a DataTables API instance to a plain array - e.g.:

    table.rows().data().toArray();
    

    Allan

  • pmengopmengo Posts: 74Questions: 37Answers: 2
    edited May 2017

    Thanks Allan. The problem is when there is 50k records , this is a expensive operation blocking the UI for long time...
    Is there a way to set the data without obj.tbl.rows.add(obj['backupAllData']) ?
    Like obj.tbl.data=alldata ? what about aadata?

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    It will take a finite amount of time of course - but all it does is a slice so it should be fairly quick.

    data() and rows().data() are the public API methods to get the data for the table.

    Allan

This discussion has been closed.