From 7f04b7ffb57f9333b3a4fe1370e0b07e11f0e9dc Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Wed, 15 Sep 2010 10:29:03 +0100 Subject: [PATCH] Fixed: When infinite scrolling, DataTables would clear it's internal cache of rows on every draw, when server-side processing was being used. This could result in fnGetNodes giving only a subset of the nodes which are visible, rather than the full set (which it now does). --- media/js/jquery.dataTables.js | 6 +- .../tests_onhold/1_dom/bInfiniteScroll.js | 45 +++++++- .../4_server-side/bInfiniteScroll.js | 102 ++++++++++++++++++ 3 files changed, 149 insertions(+), 4 deletions(-) diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index 1afaaa72..ee7df1f3 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -3189,7 +3189,11 @@ } } - _fnClearTable( oSettings ); + if ( !oSettings.oScroll.bInfinite || + (oSettings.oScroll.bInfinite && (oSettings.bSorted || oSettings.bFiltered)) ) + { + _fnClearTable( oSettings ); + } oSettings._iRecordsTotal = json.iTotalRecords; oSettings._iRecordsDisplay = json.iTotalDisplayRecords; diff --git a/media/unit_testing/tests_onhold/1_dom/bInfiniteScroll.js b/media/unit_testing/tests_onhold/1_dom/bInfiniteScroll.js index 3be8c4e2..ce73892b 100755 --- a/media/unit_testing/tests_onhold/1_dom/bInfiniteScroll.js +++ b/media/unit_testing/tests_onhold/1_dom/bInfiniteScroll.js @@ -21,6 +21,12 @@ $(document).ready( function () { ); oTest.fnTest( + "Get nodes", + null, + function () { return $('#example tbody>tr').length == 10; } + ); + + oTest.fnWaitTest( "Scroll on 20px adds 10 rows", function () { $('div.dataTables_scrollBody').scrollTop(20); }, function () { return $('#example tbody tr').length == 20; } @@ -32,6 +38,12 @@ $(document).ready( function () { function () { return $('#example_info').html() == "Showing 1 to 20 of 57 entries"; } ); + oTest.fnTest( + "Get nodes after 20px scroll", + null, + function () { return $('#example tbody>tr').length == 20; } + ); + oTest.fnTest( "Scroll on 10px more results in the same number of rows", function () { $('div.dataTables_scrollBody').scrollTop(30); }, @@ -44,7 +56,7 @@ $(document).ready( function () { function () { return $('#example_info').html() == "Showing 1 to 20 of 57 entries"; } ); - oTest.fnTest( + oTest.fnWaitTest( "Scroll to 240px adds another 10 rows", function () { $('div.dataTables_scrollBody').scrollTop(240); }, function () { return $('#example tbody tr').length == 30; } @@ -56,9 +68,18 @@ $(document).ready( function () { function () { return $('#example_info').html() == "Showing 1 to 30 of 57 entries"; } ); + oTest.fnTest( + "Get nodes after 240px scroll", + null, + function () { return $('#example tbody>tr').length == 30; } + ); + oTest.fnTest( "Filtering will drop back to 10 rows", - function () { oTable.fnFilter('gec') }, + function () { + $('div.dataTables_scrollBody').scrollTop(0); + oTable.fnFilter('gec') + }, function () { return $('#example tbody tr').length == 10; } ); @@ -69,23 +90,41 @@ $(document).ready( function () { ); oTest.fnTest( + "Get nodes after filtering", + null, + function () { return $('#example tbody>tr').length == 10; } + ); + + oTest.fnWaitTest( "Scroll after filtering adds 10", function () { $('div.dataTables_scrollBody').scrollTop(20); }, function () { return $('#example tbody tr').length == 20; } ); + oTest.fnTest( + "Get nodes after filtering", + null, + function () { return $('#example tbody>tr').length == 20; } + ); + oTest.fnTest( "Sorting will drop back to 10 rows", function () { oTable.fnSort([[1,'asc']]) }, function () { return $('#example tbody tr').length == 10; } ); - oTest.fnTest( + oTest.fnWaitTest( "Scroll after sorting adds 10", function () { $('div.dataTables_scrollBody').scrollTop(20); }, function () { return $('#example tbody tr').length == 20; } ); + oTest.fnTest( + "Get nodes after scrolling", + null, + function () { return $('#example tbody>tr').length == 20; } + ); + oTest.fnComplete(); } ); \ No newline at end of file diff --git a/media/unit_testing/tests_onhold/4_server-side/bInfiniteScroll.js b/media/unit_testing/tests_onhold/4_server-side/bInfiniteScroll.js index 9387afa5..046c001b 100755 --- a/media/unit_testing/tests_onhold/4_server-side/bInfiniteScroll.js +++ b/media/unit_testing/tests_onhold/4_server-side/bInfiniteScroll.js @@ -16,36 +16,126 @@ $(document).ready( function () { function () { return $('#example tbody tr').length == 10; } ); + oTest.fnTest( + "Info", + null, + function () { return $('#example_info').html() == "Showing 1 to 10 of 57 entries"; } + ); + + oTest.fnTest( + "Get nodes", + null, + function () { return $('#example tbody>tr').length == 10; } + ); + + oTest.fnTest( + "Get nodes function", + null, + function () { return $('#example').dataTable().fnGetNodes().length == 10; } + ); + oTest.fnWaitTest( "Scroll on 20px adds 10 rows", function () { $('div.dataTables_scrollBody').scrollTop(20); }, function () { return $('#example tbody tr').length == 20; } ); + oTest.fnTest( + "Info after 20px scroll", + null, + function () { return $('#example_info').html() == "Showing 1 to 20 of 57 entries"; } + ); + + oTest.fnTest( + "Get nodes after 20px scroll", + null, + function () { return $('#example tbody>tr').length == 20; } + ); + + oTest.fnTest( + "Get nodes function after 20px scroll", + null, + function () { return $('#example').dataTable().fnGetNodes().length == 20; } + ); + oTest.fnWaitTest( "Scroll on 10px more results in the same number of rows", function () { $('div.dataTables_scrollBody').scrollTop(30); }, function () { return $('#example tbody tr').length == 20; } ); + oTest.fnTest( + "Info after 10 more px scroll", + null, + function () { return $('#example_info').html() == "Showing 1 to 20 of 57 entries"; } + ); + oTest.fnWaitTest( "Scroll to 240px adds another 10 rows", function () { $('div.dataTables_scrollBody').scrollTop(240); }, function () { return $('#example tbody tr').length == 30; } ); + oTest.fnTest( + "Info after 240px scroll", + null, + function () { return $('#example_info').html() == "Showing 1 to 30 of 57 entries"; } + ); + + oTest.fnTest( + "Get nodes after 240px scroll", + null, + function () { return $('#example tbody>tr').length == 30; } + ); + + oTest.fnTest( + "Get nodes function after 240px scroll", + null, + function () { return $('#example').dataTable().fnGetNodes().length == 30; } + ); + oTest.fnWaitTest( "Filtering will drop back to 10 rows", function () { oTable.fnFilter('gec') }, function () { return $('#example tbody tr').length == 10; } ); + oTest.fnTest( + "Info after filtering", + null, + function () { return $('#example_info').html() == "Showing 1 to 10 of 20 entries (filtered from 57 total entries)"; } + ); + + oTest.fnTest( + "Get nodes after filtering", + null, + function () { return $('#example tbody>tr').length == 10; } + ); + + oTest.fnTest( + "Get nodes function after filtering", + null, + function () { return $('#example').dataTable().fnGetNodes().length == 10; } + ); + oTest.fnWaitTest( "Scroll after filtering adds 10", function () { $('div.dataTables_scrollBody').scrollTop(20); }, function () { return $('#example tbody tr').length == 20; } ); + oTest.fnTest( + "Get nodes after filtering", + null, + function () { return $('#example tbody>tr').length == 20; } + ); + + oTest.fnTest( + "Get nodes function after filtering", + null, + function () { return $('#example').dataTable().fnGetNodes().length == 20; } + ); + oTest.fnWaitTest( "Sorting will drop back to 10 rows", function () { oTable.fnSort([[1,'asc']]) }, @@ -58,6 +148,18 @@ $(document).ready( function () { function () { return $('#example tbody tr').length == 20; } ); + oTest.fnTest( + "Get nodes after scrolling", + null, + function () { return $('#example tbody>tr').length == 20; } + ); + + oTest.fnTest( + "Get nodes function after scrolling", + null, + function () { return $('#example').dataTable().fnGetNodes().length == 20; } + ); + oTest.fnComplete(); } ); \ No newline at end of file