Fixes #2995 - Sorting overviews sometimes causes columns to jump
This commit is contained in:
parent
f54df50154
commit
8c7ac9143f
1 changed files with 19 additions and 36 deletions
|
@ -97,8 +97,6 @@ class App.ControllerTable extends App.Controller
|
||||||
checkBoxColWidth: 30
|
checkBoxColWidth: 30
|
||||||
radioColWidth: 22
|
radioColWidth: 22
|
||||||
sortableColWidth: 36
|
sortableColWidth: 36
|
||||||
destroyColWidth: 70
|
|
||||||
cloneColWidth: 70
|
|
||||||
|
|
||||||
events:
|
events:
|
||||||
'click .js-sort': 'sortByColumn'
|
'click .js-sort': 'sortByColumn'
|
||||||
|
@ -307,9 +305,9 @@ class App.ControllerTable extends App.Controller
|
||||||
explanation: @explanation
|
explanation: @explanation
|
||||||
)
|
)
|
||||||
|
|
||||||
renderTableFull: (rows) =>
|
renderTableFull: (rows, options = {}) =>
|
||||||
@log 'debug', 'table.renderTableFull', @orderBy, @orderDirection
|
@log 'debug', 'table.renderTableFull', @orderBy, @orderDirection
|
||||||
@tableHeaders()
|
@tableHeaders(options)
|
||||||
@sortList()
|
@sortList()
|
||||||
bulkIds = @getBulkSelected()
|
bulkIds = @getBulkSelected()
|
||||||
container = @renderTableContainer()
|
container = @renderTableContainer()
|
||||||
|
@ -534,7 +532,7 @@ class App.ControllerTable extends App.Controller
|
||||||
return true if @overviewAttributes isnt @lastOverview
|
return true if @overviewAttributes isnt @lastOverview
|
||||||
false
|
false
|
||||||
|
|
||||||
tableHeaders: =>
|
tableHeaders: (options = {}) =>
|
||||||
orderBy = @customOrderBy || @orderBy
|
orderBy = @customOrderBy || @orderBy
|
||||||
orderDirection = @customOrderDirection || @orderDirection
|
orderDirection = @customOrderDirection || @orderDirection
|
||||||
|
|
||||||
|
@ -557,9 +555,11 @@ class App.ControllerTable extends App.Controller
|
||||||
if !attribute.style
|
if !attribute.style
|
||||||
attribute.style = {}
|
attribute.style = {}
|
||||||
|
|
||||||
if attributeName is item
|
if attributeName is item || (attributeName is "#{item}_id" || attributeName is "#{item}_ids")
|
||||||
# e.g. column: owner
|
# e.g. column: owner
|
||||||
headerFound = true
|
headerFound = true
|
||||||
|
|
||||||
|
if !options.skipHeadersResize
|
||||||
if @headerWidth[attribute.name]
|
if @headerWidth[attribute.name]
|
||||||
attribute.displayWidth = @headerWidth[attribute.name] * availableWidth
|
attribute.displayWidth = @headerWidth[attribute.name] * availableWidth
|
||||||
else if !attribute.width
|
else if !attribute.width
|
||||||
|
@ -574,25 +574,6 @@ class App.ControllerTable extends App.Controller
|
||||||
else
|
else
|
||||||
attribute.displayWidth = value
|
attribute.displayWidth = value
|
||||||
@headers.push attribute
|
@headers.push attribute
|
||||||
else
|
|
||||||
# e.g. column: owner_id or owner_ids
|
|
||||||
if attributeName is "#{item}_id" || attributeName is "#{item}_ids"
|
|
||||||
headerFound = true
|
|
||||||
if @headerWidth[attribute.name]
|
|
||||||
attribute.displayWidth = @headerWidth[attribute.name] * availableWidth
|
|
||||||
else if !attribute.width
|
|
||||||
attribute.displayWidth = @baseColWidth
|
|
||||||
else
|
|
||||||
# convert percentages to pixels
|
|
||||||
value = parseInt attribute.width, 10
|
|
||||||
unit = attribute.width.match(/[px|%]+/)[0]
|
|
||||||
|
|
||||||
if unit is '%'
|
|
||||||
attribute.displayWidth = value / 100 * availableWidth
|
|
||||||
else
|
|
||||||
attribute.displayWidth = value
|
|
||||||
@headers.push attribute
|
|
||||||
|
|
||||||
|
|
||||||
# execute header callback
|
# execute header callback
|
||||||
if @callbackHeader
|
if @callbackHeader
|
||||||
|
@ -647,6 +628,7 @@ class App.ControllerTable extends App.Controller
|
||||||
click: @toggleActionDropdown
|
click: @toggleActionDropdown
|
||||||
|
|
||||||
@calculateHeaderWidths()
|
@calculateHeaderWidths()
|
||||||
|
@storeHeaderWidths()
|
||||||
|
|
||||||
@columnsLength = @headers.length
|
@columnsLength = @headers.length
|
||||||
if @checkbox || @radio
|
if @checkbox || @radio
|
||||||
|
@ -841,8 +823,12 @@ class App.ControllerTable extends App.Controller
|
||||||
|
|
||||||
availableWidth = @availableWidth
|
availableWidth = @availableWidth
|
||||||
|
|
||||||
widths = @getHeaderWidths()
|
# ensure all widths are integers
|
||||||
shrinkBy = Math.ceil (widths - availableWidth) / @getShrinkableHeadersCount()
|
@headers = _.map @headers, (col) ->
|
||||||
|
col.displayWidth = Math.floor(col.displayWidth)
|
||||||
|
return col
|
||||||
|
|
||||||
|
shrinkBy = Math.ceil (@getHeaderWidths() - availableWidth) / @getShrinkableHeadersCount()
|
||||||
|
|
||||||
# make all cols evenly smaller
|
# make all cols evenly smaller
|
||||||
@headers = _.map @headers, (col) =>
|
@headers = _.map @headers, (col) =>
|
||||||
|
@ -878,12 +864,6 @@ class App.ControllerTable extends App.Controller
|
||||||
if @dndCallback
|
if @dndCallback
|
||||||
widths += @sortableColWidth
|
widths += @sortableColWidth
|
||||||
|
|
||||||
if @destroy
|
|
||||||
widths += @destroyColWidth
|
|
||||||
|
|
||||||
if @clone
|
|
||||||
widths += @cloneColWidth
|
|
||||||
|
|
||||||
widths
|
widths
|
||||||
|
|
||||||
setHeaderWidths: =>
|
setHeaderWidths: =>
|
||||||
|
@ -900,6 +880,8 @@ class App.ControllerTable extends App.Controller
|
||||||
for header in @headers
|
for header in @headers
|
||||||
widths[header.name] = header.displayWidth / @availableWidth
|
widths[header.name] = header.displayWidth / @availableWidth
|
||||||
|
|
||||||
|
@headerWidth = widths
|
||||||
|
|
||||||
App.LocalStorage.set(@preferencesStoreKey(), { headerWidth: widths }, @Session.get('id'))
|
App.LocalStorage.set(@preferencesStoreKey(), { headerWidth: widths }, @Session.get('id'))
|
||||||
|
|
||||||
onResize: =>
|
onResize: =>
|
||||||
|
@ -911,6 +893,7 @@ class App.ControllerTable extends App.Controller
|
||||||
@availableWidth = localWidth
|
@availableWidth = localWidth
|
||||||
localDelay = =>
|
localDelay = =>
|
||||||
localSetHeaderWidths = =>
|
localSetHeaderWidths = =>
|
||||||
|
@availableWidth = @el.width()
|
||||||
@setHeaderWidths()
|
@setHeaderWidths()
|
||||||
App.QueueManager.add('tableRender', localSetHeaderWidths)
|
App.QueueManager.add('tableRender', localSetHeaderWidths)
|
||||||
App.QueueManager.run('tableRender')
|
App.QueueManager.run('tableRender')
|
||||||
|
@ -953,8 +936,8 @@ class App.ControllerTable extends App.Controller
|
||||||
|
|
||||||
# switch to percentage
|
# switch to percentage
|
||||||
resizeBaseWidth = @resizeTargetLeft.parents('table').width()
|
resizeBaseWidth = @resizeTargetLeft.parents('table').width()
|
||||||
leftWidth = @resizeTargetLeft.width() / resizeBaseWidth
|
leftWidth = @resizeTargetLeft.outerWidth() / resizeBaseWidth
|
||||||
rightWidth = @resizeTargetRight.width() / resizeBaseWidth
|
rightWidth = @resizeTargetRight.outerWidth() / resizeBaseWidth
|
||||||
|
|
||||||
leftColumnKey = @resizeTargetLeft.attr('data-column-key')
|
leftColumnKey = @resizeTargetLeft.attr('data-column-key')
|
||||||
rightColumnKey = @resizeTargetRight.attr('data-column-key')
|
rightColumnKey = @resizeTargetRight.attr('data-column-key')
|
||||||
|
@ -1003,7 +986,7 @@ class App.ControllerTable extends App.Controller
|
||||||
@preferencesStore('order', 'customOrderBy', @orderBy)
|
@preferencesStore('order', 'customOrderBy', @orderBy)
|
||||||
@preferencesStore('order', 'customOrderDirection', @orderDirection)
|
@preferencesStore('order', 'customOrderDirection', @orderDirection)
|
||||||
render = =>
|
render = =>
|
||||||
@renderTableFull()
|
@renderTableFull(false, skipHeadersResize: true)
|
||||||
App.QueueManager.add('tableRender', render)
|
App.QueueManager.add('tableRender', render)
|
||||||
App.QueueManager.run('tableRender')
|
App.QueueManager.run('tableRender')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue