Why does my table takes so much time to render (1000 documents+)
Why does my table takes so much time to render (1000 documents+)
Noxcius
Posts: 7Questions: 1Answers: 0
So i'm using this plug-in which is really good, but when i try to render some amount of documents ( 1000 + ) from mongo, it takes really a lot of time.
i'm having this project in class where i need to render a table with at least 5000 documetns, but it takes about 12 second+ for the table to render.
I would like to know if there is any way to make it render faster because it is very important to me.
This discussion has been closed.
Answers
I believe we are going to need a bit more information to assist. Things that would help:
1) Is the db hosted on a different computer than what is running the webpage?
2) When you say render 'documents', what do you mean?
3) Please post the JS you are using to render the table
4) Please post the sql you are using to retrieve the data
This section of the FAQ should help, it discusses various techniques to improve performance,
Cheers,
Colin
@wblakenc
DB is hosted in heroku server, soon will be transferred to amazon server (very powerful server, the respond arrives very fast.
when i say "Documents" i mean items that are coming from the DB (array of objects)
the js i'm using is -
First i retrieve all the data from the server (as an array)
im building the table with all the thead and tbody (manipulating the data and determing the headers)
I'm not using SQL i'm using mongodb + nodejs server, and there is no query - i'm just getting all the docs from the DB.
the docs can be from 1 to 100k.
it is really important to me that it will be fast, i want to transfer it to server side Data table but i cant find any good documentation for nodejs server.
Instead of adding the array to the DOM and building the table. Try using the
data
option, like this example:https://datatables.net/examples/data_sources/js_array.html
The
deferRender
option may then help.Kevin
Also look at using
columns.render
to do the formatting instead of iterating the array to format first. Might save some time.Kevin
@kthorngren
Thank you for the response.
i'm manipulating each data set to my needs, can i do it in the columns render method?
and please explain why your way will improve the performance.
@kthorngren anyway, i think i'm gonna have to switch it to server side rendering.
i need it to be super fast, (handling also 100k of documents)...
Read the
deferRender
docs to understand how it will help with Javascript data.That depends on what you are doing. Take a look at the
columns.render
docs to see what it does. Also this example.The suggestion is to save one iteration though the data. Datatables loops through the data. If you also loop through the data then that is twice through the dataset.
Thats a good idea.
Kevin
@kthorngren
The problem is that i can't find any decent docs for that - or some examples online...
This example includes all the necessary code:
https://datatables.net/examples/data_sources/server_side.html
The protocol is discussed here.
Colin
What specifically are you referring to?
I've pointed you to Datatables specific docs and examples. Please provide more specific questions. If you have questions about how Datatables can render your data then please provide an example of the data and how you would like it rendered.
Kevin
@kthorngren
First i'm fetching all products from the server (can be 1000 docs, can be 50k docs).
then i'm sending them to function that sets the table -
each product going some small manipulation - and then i build a table row for each product with this function -
each product gets he's own row and then im appending the tablehead and tablebody -
and than
that's the flow it needs to go.
It looks like you're forming a HTML row. You shouldn't need to do that if you just render the data like this example here. And if you use
serverSide
, then it would only be rendering those rows on the visible page.Colin
@colin but i need to be that way...
i can't understand how is your example can help me achieve what i want