Is there a way to dynamically draw more of the rows in the data set as you scroll down
Is there a way to dynamically draw more of the rows in the data set as you scroll down
gordyr
Posts: 35Questions: 0Answers: 0
Hi,
I am well aware of the built in scrolling facilities of within dataTables, however this case is specific and doesn't appear to be covered by these methods.
The best way to describe what I am trying to do is to describe the behaviour I wish to emulate.
If you take a look at Facebook's sidebar, the top half gives you live updates. It seems to load about 25 of these rows into the dom. Then if you scroll down to the bottom, it renders more rows, scroll down again and another set are loaded. Each time they are simply added to the dom.
This behaviour is covered within datatables via the scroller plugin and infinite scrolling methods. However both of these solutions require a fixed viewport (scrollY). Like facebooks sidebar mine is a resizable div rendering these methods unusable.
For this this sidebar I am using client side processing. I am pulling in all of the data in one request. Is there any way, via the datatables api or otherwise, that I can add this kind of behaviour? I currently have all rows being drawn in to the DOM by setting the iDisplaylength to '999999'. Obviously this is not optimal if a user ends up with a huge amount of rows to render in one hit.
Any ideas?
I am well aware of the built in scrolling facilities of within dataTables, however this case is specific and doesn't appear to be covered by these methods.
The best way to describe what I am trying to do is to describe the behaviour I wish to emulate.
If you take a look at Facebook's sidebar, the top half gives you live updates. It seems to load about 25 of these rows into the dom. Then if you scroll down to the bottom, it renders more rows, scroll down again and another set are loaded. Each time they are simply added to the dom.
This behaviour is covered within datatables via the scroller plugin and infinite scrolling methods. However both of these solutions require a fixed viewport (scrollY). Like facebooks sidebar mine is a resizable div rendering these methods unusable.
For this this sidebar I am using client side processing. I am pulling in all of the data in one request. Is there any way, via the datatables api or otherwise, that I can add this kind of behaviour? I currently have all rows being drawn in to the DOM by setting the iDisplaylength to '999999'. Obviously this is not optimal if a user ends up with a huge amount of rows to render in one hit.
Any ideas?
This discussion has been closed.
Replies
Or virtual scrolling: http://datatables.net/extras/scroller/
Allan
Yes I am aware of these but they do not work in this situation due to their requirement of having a fixed height container via the scrollY setting.
Unless of course are you suggesting that I can dynamically modify the scrollY setting as the containers resize??
Allan
Sorry I'm really struggling to articulate this.
Allan
My thoughts are.
- Limit the initial GET request to 20 records.
- Attach an event request that performs a POST when you scroll to the bottom that sends the row index to retrieve i.e 21-40, then 41-60 etc.
- Rewrite my server side code to receive those parameters and spit out the JSON of those particular rows.
- On success, loop through the array and add each row manually into the table. Which is easy as I already have written the code to do that.
It's actually quite simple when you think about it
Regardles... I won't be tackling this until after the weekend. But i'll be sure to post up my code when I get it done. Cheers as always!
I have solved it completely and have a fully working solution. The code is very specific to my application therefore I'm not going to copy it all out here. However, if someone else is looking for an explanation of how this can be achieved I will try to refactor it into something more generic and post it up. I'm subscribed to this thread so will get a notification of any requests straight away.
Thanks again for such a versatile plugin Allan.