Scrolling feedback seems totally messed up - doesn't track scrolling properly
Scrolling feedback seems totally messed up - doesn't track scrolling properly
Link to test case:
None, see attached video below.
Debugger code (debug.datatables.net):
Cannot load debugger into Firefox, either as a bookmarklet nor via snippet in console.
Version 1.13.4 of datatables, 2.1.1 Scroller extension, jQuery 3.7.0.
Table initialized like this:
table = $('#ti-table').DataTable({
ajax: '/get/my/data',
scrollY: tbh,
deferRender: true,
serverSide: true,
processing: true,
ordering: false,
searching: true,
scroller: true
});
Error messages shown:
None.
Description of problem:
Feedback "Showing 1 to n of N entries" seems highly inaccurate - showing negative numbers sometimes, etc. See this mp4:
Note that even the initial scrolling of just a few rows shows no feedback. Note that this data is already prefetched in the browser by the initial AJAX call.
This question has accepted answers - jump to:
Answers
Scroller 2.1.1 and Datatables 1.13.4 seems to work correctly in this SSP Example. The values displayed in the info element come from the values in the
recordsTotal
andrecordsFiltered
in the JSON response. See the SSP protocol docs for more info.I would start by using the browser's Network inspector tool to monitor the JSON response. Compare it to the values in the info element as you scroll. If they are the same then the server script is responding with incorrect values.
If you still need help please provide a link to your page or a test case replicating the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
As a test try turning off the Scroller. Is the info element correct when you page through the table?
Are you using a Datatables supplied Server Side Processing script?
Kevin
Here is a link to a page which displays the problem:
https://app1.red-dove.com/
The table is on a page in a hidden tab (this affects how it needs to be initialized). From the above page, click "Grid tests" in the sidebar on the left and then on the "Test Stuff (Work in progress)" tab. You can see the table initialization in the testingreds.js file snippet. I'm using Firefox 114.0.
I'm not using explicit pagination, I'm looking for an "infinite scroll" type of operation, which is why I'm using the
scroller
.I'm not using a Datatables provided script, but this is the initial JSON response (formatted for easier reading):
Notice that if you use the mouse scroll wheel to scroll the table contents, it scrolls OK, but the Datatables footer shows "Showing 1 to 5 of 3,469,032 entries" even when you scroll so that the top row is 2, 3, 4 etc.
It's a small window (5 rows) in my example because of the developer pane taking up part of the browser window, plus I'm using a largeish font size.
I also had to reduce the
scrollY
value given to Datatables, otherwise the "Showing 1 to 5 of 3,469,032 entries" doesn't appear.Thanks,
Vinay
Here is a link to a page which displays the problem:
https://app1.red-dove.com/
The table is on a page in a hidden tab pane (this affects how it needs to be initialized). From the above page, click "Grid tests" in the sidebar on the left and then on the "Test Stuff (Work in progress)" tab. You can see the table initialization in the testingreds.js file snippet. I'm using Firefox 114.0.
I'm posting this reponse anew, the Internet seems to have swallowed up my previous attempt!
I'm not using explicit pagination - I want an "infinite scroll" type of user interaction, which is why I'm using the Scroller extension.
I'm not using a Datatables-provided SSP script, but the response provided from the server seems reasonable (formatted for easier reading):
Note that if you use the mouse wheel to scroll inside the table, the contents scroll OK, but the Datatables footer still shows e.g. "Showing 1 to 5 of 3,469,032 entries" even when you scroll so that the top row visible is not 1 but 2, 3, 4 etc.
I also had to kludge the
scrollY
passed to Datatables, otherwise the "Showing 1 to 5 of 3,469,032 entries" doesn't appear in the visible part of the window.Yes, I understand thats why I said "As a test try turning off the Scroller.".
Not sure if it will help but try using the correct
scroller.bootstrap4.min.css
as mentioned in your other thread. Not sure but it may have an impact on how Datatables calculates the display.If not then @allan will need to take a look.
Kevin
A scrolling container, inside a scrolling container, inside a scrolling container. Nice!
You have:
in your CSS. That is almost certainly at least part of the issue. Remove the
scrollable
class from yourtable
so that doesn't apply and just let DataTables' own scrolling do what it needs to do.display: block
does not work for thetbody
- it causes all sorts of problems, such as the column alignment you are seeing.Allan
I know. Modern websites these days, eh?
OK, I'll try that. It works well for scrollable content which is modest in size and doesn't require client-side support, but I can see why Datatables would expect to be in full control of its scrolling.
Thank you Allan & Kevin for your help. I will try your suggestions and see how i get on.
I've incorporated your suggestions, and my test page is looking a lot better - the scrolling and the column width issues are gone (thank you!). There are, however, some problems remaining, as illustrated by the first image below.
scrollY
value as an option, the "Showing m to n of N entries" doesn't appear, as it's clipped out of view. To get it to appear, I kludged the height by subtracting 180 pixels, after which it does appear.Is there anything I can do to remove these problems? I'd be grateful for some hints on these, just as I am grateful for your quick responses to my questions.
1) On your
id="ti-table-container"
element add the classcontainer
, as that is required by Bootstrap if you are going to have a grid layout (which DataTables uses). The grid adds -15px left and right margins which is causing the horizontal overflow.Also remove the
overflow-auto
class. And I would suggest you take a look at this blog post to have DataTables automatically fit the scroll container into the available area. It requires a little integration work, but I think it would be worth it for the layout you are creating.2 and 3) Should be fixed by the above.
4) Handling this automatically will be in DataTables 2 (ready when it is ready... ). For now you probably need to modify the
dom
property which usescol-md-5
for the information column. Since you don't have any paging, you can just usecol-md-12
for that one.Allan
Great, thanks for those suggestions. They address the extraneous scrollbars, the search box positioning and the wrapping of the information column. However, perhaps because I removed the
overflow-auto
class, the table now exceeds the bounds of the window vertically, and you have to scroll down to see the information column and my other information panel which on this test page I've labelled with "Footer bit under table", and which I'd like visible at the foot of the table when the tab first opens. I realise that thescrollY
value I passed (which was the original height of#ti-table-container
) is used by Datatables not for the whole table, but for just the scrolling areadiv.datatables_scrollBody
. How do I get it so that Datatables limits the vertical height of the entire component to a value passed in via options? I don't see an option which allows you to set the overall vertical height of the Datatables component for this use case.This is why I set up those multiple scrolling areas on my page - so that stuff such as would be in the place of "Footer bit under table" would be visible in the page right away, not requiring one to scroll down to see it.Did you try the scroll resize component in the blog post I linked to? That would resolve that. It basically sets
scrollY
dynamically.Allan
D'oh no, I didn't! Sorry for the noise.
I have now added the
ScrollResize
andPageResize
plugins and configured withand the table still overflows the container. I'm not sure what additional integration work I need to do - please advise.
You need to set the height over your
id=ti-table-container
element to the correct height for the space available. The scrollResize plug-in will automatically restrict the table to that height, however if the container is allow to go to any height, then it will take as much as needed!For example if I pop open the console and add a height of 200px to that element, then it works correctly.
You need to update your layout to fit that space exactly. That's beyond the scope of the support I can provide I'm afraid since it is generic CSS layout, but you might want to look into grid layout.
Also, don't use both scrollResize and pageResize at the same time.
Allan
When the Datatable is initialized, the height of
#ti-table-container
is (on my machine) 621 - as determined by CSS. However, because I set it up with acontainer
class rather thanoverflow-auto
as per your suggestion above, then I guess the container is free to grow vertically. So I just did a$('#ti-table-container').height(tbh)
wheretbh
was just before obtained using$('#ti-table-container').height()
. This works in this simple test scenario, but it does seem odd to force the height in this way using astyle=height: XXX
override, rather than letting CSS take care of it. On a window resize, normally CSS would sort out the relative heights of everything, but not once a value is explicitly set.That's the key bit. If you don't set a height, then it will grow vertically. Also, we don't want the container scrolling, so
overflow: auto
isn't the right solution.The best way to handle it, as I say would be with CSS grids. That's how I would implement this myself. Absolutely positioned elements inside a relative container would be another option, but a grid would be much easier I think.
Allan
OK, thanks,