@@ -26,7 +26,7 @@ public function it_can_set_total_records()
2626 $ crawler ->assertJson ([
2727 'draw ' => 0 ,
2828 'recordsTotal ' => 10 ,
29- 'recordsFiltered ' => 20 ,
29+ 'recordsFiltered ' => 10 ,
3030 ]);
3131 }
3232
@@ -37,7 +37,7 @@ public function it_can_set_zero_total_records()
3737 $ crawler ->assertJson ([
3838 'draw ' => 0 ,
3939 'recordsTotal ' => 0 ,
40- 'recordsFiltered ' => 20 ,
40+ 'recordsFiltered ' => 0 ,
4141 ]);
4242 }
4343
@@ -91,7 +91,27 @@ public function it_can_perform_global_search()
9191 #[Test]
9292 public function it_can_skip_total_records_count_query ()
9393 {
94- $ crawler = $ this ->call ('GET ' , '/query/simple ' , [
94+ DB ::enableQueryLog ();
95+
96+ $ crawler = $ this ->call ('GET ' , '/skip-total-records ' );
97+ $ crawler ->assertJson ([
98+ 'draw ' => 0 ,
99+ 'recordsTotal ' => 20 ,
100+ 'recordsFiltered ' => 20 ,
101+ ]);
102+
103+ DB ::disableQueryLog ();
104+ $ queryLog = DB ::getQueryLog ();
105+
106+ $ this ->assertCount (2 , $ queryLog );
107+ }
108+
109+ #[Test]
110+ public function it_can_skip_total_records_count_query_with_filter_applied ()
111+ {
112+ DB ::enableQueryLog ();
113+
114+ $ crawler = $ this ->call ('GET ' , '/skip-total-records ' , [
95115 'columns ' => [
96116 ['data ' => 'name ' , 'name ' => 'name ' , 'searchable ' => 'true ' , 'orderable ' => 'true ' ],
97117 ['data ' => 'email ' , 'name ' => 'email ' , 'searchable ' => 'true ' , 'orderable ' => 'true ' ],
@@ -101,9 +121,14 @@ public function it_can_skip_total_records_count_query()
101121
102122 $ crawler ->assertJson ([
103123 'draw ' => 0 ,
104- 'recordsTotal ' => 0 ,
124+ 'recordsTotal ' => 1 ,
105125 'recordsFiltered ' => 1 ,
106126 ]);
127+
128+ DB ::disableQueryLog ();
129+ $ queryLog = DB ::getQueryLog ();
130+
131+ $ this ->assertCount (2 , $ queryLog );
107132 }
108133
109134 #[Test]
@@ -393,8 +418,6 @@ protected function setUp(): void
393418 ->formatColumn ('created_at ' , new DateFormatter ('Y-m-d ' ))
394419 ->toJson ());
395420
396- $ router ->get ('/query/simple ' , fn (DataTables $ dataTable ) => $ dataTable ->query (DB ::table ('users ' ))->skipTotalRecords ()->toJson ());
397-
398421 $ router ->get ('/query/addColumn ' , fn (DataTables $ dataTable ) => $ dataTable ->query (DB ::table ('users ' ))
399422 ->addColumn ('foo ' , 'bar ' )
400423 ->toJson ());
@@ -463,6 +486,10 @@ protected function setUp(): void
463486 ->setTotalRecords (0 )
464487 ->toJson ());
465488
489+ $ router ->get ('/skip-total-records ' , fn (DataTables $ dataTable ) => $ dataTable ->query (DB ::table ('users ' ))
490+ ->skipTotalRecords ()
491+ ->toJson ());
492+
466493 $ router ->get ('/set-filtered-records ' , fn (DataTables $ dataTable ) => $ dataTable ->query (DB ::table ('users ' ))
467494 ->setFilteredRecords (10 )
468495 ->toJson ());
0 commit comments