What could prevent pagination from working?
What could prevent pagination from working?
I have a DOM sourced table and pagination is currently not working. I have 25000 rows and loading is taking forever. The rows are created via a Django/Python for loop. Sorting is also not working.
var page = $(document).ready(function() {
// Creates not reviewed table
var not_reviewed = $('#not-reviewed').DataTable({
// 'ajax': {
// 'url': '/blacklist',
// 'type': 'GET'
// 'dataSrc': '',
// },
// 'columns': [
// {'candidate_data': 'query'},
// {'candidate_data': 'tag'},
// {'candidate_data': 'counts.central'},
// {'candidate_data': 'counts.relevant'},
// {'candidate_data': 'counts.offTopic'},
// {'candidate_data': 'status'},
// {'candidate_data': 'lang'},
// {'candidate_data': },
// ],
'fontFamily': 'Roboto',
'lengthMenu': [[10, 25, 50, 75, -1], [10, 25, 50, 75, 'All']],
'paging': true,
'pagingType': 'full_numbers',
'searching': false,
'search': {'smart': true},
'ordering': false,
'serverSide': true,
'deferLoading': 26517,
'processing': true,
'deferRender': true,
columnDefs: [
{
'searchable': true,
'orderable': true,
'className': 'dt-head-center',
'targets': '_all',
},
{'visible': false, 'targets': [-1, -2]}
],
'order': [[1, 'asc']],
fixedHeader: {header: false, footer: true},
stateSave: true
});
// Creates reviewed table
var reviewed = $('#reviewed').DataTable({
// 'columns': [
// {'candidate_data': 'query'},
// {'candidate_data': 'tag'},
// {'candidate_data': 'counts.central'},
// {'candidate_data': 'counts.relevant'},
// {'candidate_data': 'counts.offTopic'},
// {'candidate_data': 'status'},
// {'candidate_data': 'lang'},
// {'candidate_data': },
// ],
'lengthMenu': [[10, 25, 50, 75, -1], [10, 25, 50, 75, 'All']],
'paging': true,
'pagingType': 'full_numbers',
'searching': true,
'search': {'smart': true},
'ordering': true,
'serverSide': true,
'deferLoading': 26517,
'processing': true,
'deferRender': true,
columnDefs: [
{
'searchable': true,
'orderable': true,
'className': 'dt-head-center',
'targets': '_all',
},
{'visible': false, 'targets': [-1, -2]}
],
'order': [[1, 'asc']],
fixedHeader: {header: false, footer: true},
stateSave: true
});
Answers
Generally when Datatables features aren't working you will find an error in your browser's console.
Also I see
serverSide: true
in both tables. This isn't doing anything for you since you are loading the data into the DOM. For this to work you would need to use theajax
option and have it fetch the data from your server. Your Django/Python code would then need to support the server side processing model described here:https://datatables.net/manual/server-side
The
deferRender
option isn't going to help either. It only works with ajax os Javascript loaded data.Not knowing anymore about your environment I would probably try fetching the data via the
ajax
option in Datatables and start withdeferRender
and remove theserverSide
option. The delay will be in fetching the 25000 rows then Datatables will only create the HTML for the rows being displayed. All the searching and sorting will be done in the client.If that's too slow then I would look at server side processing but you will need to find or write Python code to support the sorting, searching and paging functions.
Kevin
Thanks for the response.