Skip to content

Commit 10aa5eb

Browse files
committed
Add force refresh option and improve abort handling in pivot table rendering
- Introduced `forceRefresh` option to allow forced rendering even after an abort. - Enhanced abort functionality to display a message and a refresh button when rendering is aborted. - Updated abort function to accept a message for more informative user feedback. - Adjusted rendering logic to conditionally handle abort states based on the `forceRefresh` option.
1 parent 3201b92 commit 10aa5eb

File tree

5 files changed

+109
-38
lines changed

5 files changed

+109
-38
lines changed

dist/pivot.js

Lines changed: 58 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pivot.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pivot.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pivot.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pivot.coffee

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ callWithJQuery ($) ->
533533
pivotTableRendererAsync = (pivotData, opts) ->
534534
startTime = Date.now()
535535
aborted = false
536+
forceRefresh = opts.forceRefresh || false
536537

537538
return new Promise (resolve, reject) ->
538539
try
@@ -570,9 +571,12 @@ callWithJQuery ($) ->
570571
endIndex: metadata?.endIndex
571572
}
572573

574+
abortMessage = null
573575
abortFn = null
574576
if stage in ['render-started', 'render-progress']
575-
abortFn = -> aborted = true
577+
abortFn = (message) ->
578+
aborted = true
579+
abortMessage = message if message?
576580

577581
toggleVirtualizationFn = null
578582
if stage in ['render-started']
@@ -603,7 +607,13 @@ callWithJQuery ($) ->
603607
estimatedVisibleRows: estimatedVisibleRows
604608
})
605609

606-
return resolve($("<div>").text("Rendering aborted by user")[0]) if aborted
610+
if aborted and not forceRefresh
611+
# Show refresh button and display abort message
612+
@find(".pvtRefreshBtn").show()
613+
defaultMessage = "Rendering aborted by user.<br>Click refresh button to force rendering."
614+
message = abortMessage || defaultMessage
615+
abortElement = $("<div style='text-align: center; padding: 20px; color: #666;'><i class='fas fa-exclamation-triangle'></i><br>#{message}</div>")[0]
616+
return resolve(abortElement)
607617

608618
shouldVirtualize = opts.table.virtualization.enabled
609619

@@ -717,7 +727,13 @@ callWithJQuery ($) ->
717727
result.appendChild thead
718728

719729
callLifecycle('render-progress', 1)
720-
return resolve($("<div>").text("Rendering aborted by user")[0]) if aborted
730+
if aborted and not forceRefresh
731+
# Show refresh button and display abort message
732+
@find(".pvtRefreshBtn").show()
733+
defaultMessage = "Rendering aborted by user.<br>Click refresh button to force rendering."
734+
message = abortMessage || defaultMessage
735+
abortElement = $("<div style='text-align: center; padding: 20px; color: #666;'><i class='fas fa-exclamation-triangle'></i><br>#{message}</div>")[0]
736+
return resolve(abortElement)
721737

722738
# Async processing of data rows
723739
tbody = document.createElement("tbody")
@@ -784,7 +800,7 @@ callWithJQuery ($) ->
784800
totalRows: totalRows
785801
})
786802

787-
return if aborted
803+
return if aborted and not forceRefresh
788804

789805
currentIndex = endIndex
790806

@@ -803,7 +819,7 @@ callWithJQuery ($) ->
803819
totalRows: totalRows
804820
})
805821

806-
return if aborted
822+
return if aborted and not forceRefresh
807823

808824
#finally, the row for col totals, and a grand total
809825
if opts.table.colTotals || rowAttrs.length == 0
@@ -901,15 +917,23 @@ callWithJQuery ($) ->
901917
# totalRows: pivotData.getRowKeys().length
902918
# totalCols: pivotData.getColKeys().length
903919

920+
abortMessage = null
904921
abortFn = null
905922
toggleVirtualizationFn = null
906923
if stage in ['render-started', 'render-progress']
907-
abortFn = -> aborted = true
924+
abortFn = (message) ->
925+
aborted = true
926+
abortMessage = message if message?
908927

909928
opts.lifecycleCallback(data, abortFn, toggleVirtualizationFn)
910929

911930
callLifecycle('render-started')
912-
return $("<div>").text("Rendering aborted by user")[0] if aborted
931+
if aborted and not forceRefresh
932+
# Show refresh button and display abort message
933+
@find(".pvtRefreshBtn").show()
934+
defaultMessage = "Rendering aborted by user.<br>Click refresh button to force rendering."
935+
message = abortMessage || defaultMessage
936+
return $("<div style='text-align: center; padding: 20px; color: #666;'><i class='fas fa-exclamation-triangle'></i><br>#{message}</div>")[0]
913937

914938
colAttrs = pivotData.colAttrs
915939
rowAttrs = pivotData.rowAttrs
@@ -1679,6 +1703,7 @@ callWithJQuery ($) ->
16791703
# Передаем ссылку на UI элемент для автоопределения высоты
16801704
subopts.rendererOptions = $.extend(true, {}, opts.rendererOptions)
16811705
subopts.rendererOptions.pivotUIElement = this[0]
1706+
subopts.rendererOptions.forceRefresh = forceRefresh
16821707
#construct filter here
16831708
exclusions = {}
16841709
@find('input.pvtFilter').not(':checked').each ->
@@ -1930,6 +1955,8 @@ callWithJQuery ($) ->
19301955
###
19311956

19321957
pivotTableRendererVirtualized = (pivotData, opts) ->
1958+
forceRefresh = opts.forceRefresh || false
1959+
aborted = false
19331960
defaults =
19341961
table:
19351962
clickCallback: null
@@ -2002,9 +2029,12 @@ callWithJQuery ($) ->
20022029
endIndex: metadata?.endIndex
20032030
}
20042031

2032+
abortMessage = null
20052033
abortFn = null
20062034
if stage in ['render-started', 'render-progress']
2007-
abortFn = -> aborted = true
2035+
abortFn = (message) ->
2036+
aborted = true
2037+
abortMessage = message if message?
20082038

20092039
toggleVirtualizationFn = null
20102040
if stage in ['render-started']
@@ -2036,7 +2066,13 @@ callWithJQuery ($) ->
20362066
domElements: 0
20372067
estimatedVisibleRows: estimatedVisibleRows
20382068
})
2039-
return if aborted
2069+
if aborted and not forceRefresh
2070+
# Show refresh button and display abort message
2071+
@find(".pvtRefreshBtn").show()
2072+
defaultMessage = "Rendering aborted by user.<br>Click refresh button to force rendering."
2073+
message = abortMessage || defaultMessage
2074+
abortElement = $("<div style='text-align: center; padding: 20px; color: #666;'><i class='fas fa-exclamation-triangle'></i><br>#{message}</div>")[0]
2075+
return abortElement
20402076

20412077
shouldVirtualize = opts.table.virtualization.enabled
20422078

0 commit comments

Comments
 (0)