Scroller row counting issues
Scroller row counting issues
prubin
Posts: 26Questions: 0Answers: 0
Allan,
You have dome some remarkable work here, I have been able to integrate you work into mine and produce a very powerful generic display of an assortment of data.
Unfortunately, scroller continues to be a bit of an issue cosmetically.
I understand that scroller requires that every line be one line of text or it messes up the math to show x to y of z. I have multiple tables where the count gets off even when there is no row that is more than 1 line high.
As far as I can tell what is happening is that the measurement is off by a few pixels on every line. I am trying to work through the scroller code to narrow it down. The table I am looking at as an example displays 3344 to 2906 of 2906 entries when scrolled to the bottom and shows 8.75 rows at the top when it says 1 to 10 of 2906 entries. I have checked that the table has cellpadding 0 and cellspacing 0.
I also looking to see if there is some efficient way we could remember row heights as we scroll so as to make it self correcting when there is a row that renders high.
Can you make any recommendations on where I might focus my attention?
Thanks.
You have dome some remarkable work here, I have been able to integrate you work into mine and produce a very powerful generic display of an assortment of data.
Unfortunately, scroller continues to be a bit of an issue cosmetically.
I understand that scroller requires that every line be one line of text or it messes up the math to show x to y of z. I have multiple tables where the count gets off even when there is no row that is more than 1 line high.
As far as I can tell what is happening is that the measurement is off by a few pixels on every line. I am trying to work through the scroller code to narrow it down. The table I am looking at as an example displays 3344 to 2906 of 2906 entries when scrolled to the bottom and shows 8.75 rows at the top when it says 1 to 10 of 2906 entries. I have checked that the table has cellpadding 0 and cellspacing 0.
I also looking to see if there is some efficient way we could remember row heights as we scroll so as to make it self correcting when there is a row that renders high.
Can you make any recommendations on where I might focus my attention?
Thanks.
This discussion has been closed.
Replies
You are absolutely correct - a pixel out in the row height calculation would destroy the Scroller calculations. Might you be able to give a link (PM me by clicking on my name in the forum and picking "Send message" if you like) so I can take a look and see what might be upsettings Scroller's calculation?
Thanks,
Allan
Ok, I stuck breakpoints in fnMeasure and _fnCalcRowHeight. fmMeasure is called on page refresh which calls _fnCalcRowHeight which calculates 26 as the row height. fnMeasure then calculates a need for 3 rows as my table starts as 25 high until it fills. This happens for all three tables before any data has been loaded. All three tables on this page calculate the row height as 26px.
The tables are then loaded with data and the fnMeasure and _fnCalcRowHeight are never called again and according to FireBug Table 1 has a row height of 26, Table 2 has a height of 30px per row and Table three has a height of 22px per row.
Table 1 seems to be working as expected.
Table 2 seems to have gained 4 px per row because it is on a jQuery UI tab control which is a ui-widget and has a font-size of 1.1em;
Table 3 is also in a Tab, but I had applied a font-size:65% to the tab div because the table did not fit on the tab without.
So it seems we have a issue that I need to manually call fnMeasure again after I re-size the table to re-calculate the rows for the viewport. And _fnCalcRowHeight is not correctly calculating the row height correctly in the first place. The code is adding the test table to body and not the div that the table actually belongs to, so it does not get the correct styling. I have tried to find the original element so that I can attach to it's div instead, but during the initialization of the scroller, that element seems to be missing from the DOM and I have been unable to locate the variable that contains the original parent. that the new table will be attached to when it is created.
This needs to be the div of the tables original parent.
[code]
document.body.appendChild( nDiv );
this.s.rowHeight = $(nTr).height();
document.body.removeChild( nDiv );
[/code]
*edit* If you have a link you can give me with a demo showing the issue, that would be really helpful.
Allan
[code]
"_fnCalcRowHeight": function ()
{
var
nDiv = document.createElement('div'),
nTable = this.s.dt.nTable.cloneNode( false ),
nBody = document.createElement( 'tbody' ),
nTr = document.createElement('tr'),
nTd = document.createElement('td');
nTd.innerHTML = " ";
nTr.appendChild( nTd );
nBody.appendChild( nTr );
nTable.appendChild( nBody );
nDiv.className = this.s.dt.oClasses.sScrollBody;
nDiv.appendChild( nTable );
document.body.appendChild( nDiv );
this.s.rowHeight = $(nTr).height();
document.body.removeChild( nDiv );
},
[/code]
document.body.appendChild( nDiv ); <== needs to be parent dom object not body
Can you give me a patch to get this to the correct parent object?
Thanks
Paul.
I've just been looking into this and it actually is not possible to insert an element into the DataTables container at that point and get a measurement from it. This is because of how the sDom building works - for speed to creates the wrapper element but doesn't put it into the document until it is finished - i.e. after the initialisation of sDom is complete.
What is probably needed is for DataTables to fire an event at that point, which Scroller can listen for and the react to, but I think I'm going to have to think about it a little bit to see if there is another way.
Allan