Skip to content

Commit

Permalink
feat(js): loading visual for datatables;
Browse files Browse the repository at this point in the history
- Brought back `processing` for datatables.
- Added in pre-init visual for large data tables.
  • Loading branch information
JVickery-TBS committed Nov 8, 2023
1 parent f922ec9 commit 3226d73
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
13 changes: 13 additions & 0 deletions ckanext/datatablesview/assets/datatables_view.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ div.dataTables_scroll{
/* processing message should hover over table and be visible */
#dtprv_processing {
z-index: 100;
display: block;
}

#dtprv_processing.pre-init::after{
content: '';
display: block;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: white;
z-index: -1;
}

/* for table header, don't wrap */
Expand Down
11 changes: 10 additions & 1 deletion ckanext/datatablesview/assets/datatablesview.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,16 @@ this.ckan.module('datatables_view', function (jQuery) {
})

// init the datatable
$('#dtprv').on('preInit.dt', function (_event, _settings) {
// show loading indicator when first painting data into the table.
// useful with very large resources that take long to load
$('body.dt-view').css('visibility', 'visible');
$('#dtprv_processing').addClass('pre-init');
});
datatable = $('#dtprv').DataTable({
paging: true,
serverSide: true,
processing: false,
processing: true,
stateSave: statesaveflag,
stateDuration: stateduration,
colReorder: {
Expand Down Expand Up @@ -592,6 +598,9 @@ this.ckan.module('datatables_view', function (jQuery) {
api.page(gsavedPage)
}

// hide the pre-loading indicator background so the table is interactive when loading
$('#dtprv_processing').removeClass('pre-init');

// restore selected rows from state
if (typeof gsavedSelected !== 'undefined') {
api.rows(gsavedSelected).select()
Expand Down

0 comments on commit 3226d73

Please sign in to comment.