Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

recordsTotal, recordsFiltered explanation Jquery DataTable

Tags:

I'm reading datatable doc's but i can't find an answer. My question is:

I have a table with 10.000 rows. I do a search by state and result is 3000 rows. From 3000 rows, i'll show 20 per page.

"recordsTotal": what value should be in here?, "recordsFiltered": what value should be in here?,

If recordsTotal value must be 10.000, can i hide this value if is not interesting?

like image 522
Marcelo Agimóvel Avatar asked Apr 01 '17 19:04

Marcelo Agimóvel


People also ask

How does jQuery DataTable work?

jQuery DataTable is a powerful and smart HTML table enhancing plugin provided by jQuery JavaScript library. It is a highly flexible tool that is basically created to display information in tables as well as adding interactions to them, hence, enhancing data accessibility in HTML tables.

What is draw event in DataTable?

The draw event is fired whenever the table is redrawn on the page, at the same point as drawCallback (technically the callback fires before the event, but they occur sequentially and thus either can be used to achieve the same effect).

What is bDestroy in DataTable?

bDestroy. Show details. Replace a DataTable which matches the given selector and replace it with one which has the properties of the new initialisation object passed. If no table matches the selector, then the new DataTable will be constructed as per normal.


1 Answers

From official documentation:

recordsTotal

Total records, before filtering (i.e. the total number of records in the database)

recordsFiltered

Total records, after filtering (i.e. the total number of records after filtering has been applied - not just the number of records being returned for this page of data).

Your response should be:

{     "draw": 1,     "recordsTotal": 10000,     "recordsFiltered": 3000,     "data": [        // ... skipped 20 records ...     ] } 

I believe recordsTotal is only used for informational panel Showing 1 to 20 of 3000 entries (filtered from 10000 total entries). If you're not using informational panel, you don't have to return recordsTotal property.

Property recordsFiltered is also used by jQuery DataTables to calculate number of pages required to display your dataset.

See Server-side - Returned data for more information.

like image 150
Gyrocode.com Avatar answered Oct 05 '22 23:10

Gyrocode.com