table resize: fix that some tables have width zero while calculating
- fall back minTableWidth
This commit is contained in:
parent
5062b4022c
commit
3b463670ce
2 changed files with 11 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
||||||
class App.ControllerTable extends App.Controller
|
class App.ControllerTable extends App.Controller
|
||||||
minColWidth: 40
|
minColWidth: 40
|
||||||
baseColWidth: 130
|
baseColWidth: 130
|
||||||
|
minTableWidth: 612
|
||||||
|
|
||||||
checkBoxColWidth: 40
|
checkBoxColWidth: 40
|
||||||
radioColWidth: 22
|
radioColWidth: 22
|
||||||
|
@ -345,8 +346,13 @@ class App.ControllerTable extends App.Controller
|
||||||
table
|
table
|
||||||
|
|
||||||
adjustHeaderWidths: (headers) ->
|
adjustHeaderWidths: (headers) ->
|
||||||
|
availableWidth = @el.width()
|
||||||
|
|
||||||
|
if availableWidth is 0
|
||||||
|
availableWidth = @minTableWidth
|
||||||
|
|
||||||
widths = @getHeaderWidths headers
|
widths = @getHeaderWidths headers
|
||||||
difference = widths - @el.width()
|
difference = widths - availableWidth
|
||||||
|
|
||||||
if difference > 0
|
if difference > 0
|
||||||
# convert percentages to pixels
|
# convert percentages to pixels
|
||||||
|
@ -355,12 +361,12 @@ class App.ControllerTable extends App.Controller
|
||||||
|
|
||||||
if unit is '%'
|
if unit is '%'
|
||||||
percentage = parseInt col.width, 10
|
percentage = parseInt col.width, 10
|
||||||
col.width = percentage / 100 * @el.width() + "px"
|
col.width = percentage / 100 * availableWidth + "px"
|
||||||
|
|
||||||
return col
|
return col
|
||||||
|
|
||||||
widths = @getHeaderWidths headers
|
widths = @getHeaderWidths headers
|
||||||
shrinkBy = Math.ceil (widths - @el.width()) / @getShrinkableHeadersCount(headers)
|
shrinkBy = Math.ceil (widths - availableWidth) / @getShrinkableHeadersCount(headers)
|
||||||
|
|
||||||
# make all cols evenly smaller
|
# make all cols evenly smaller
|
||||||
headers = _.map headers, (col) =>
|
headers = _.map headers, (col) =>
|
||||||
|
@ -370,7 +376,7 @@ class App.ControllerTable extends App.Controller
|
||||||
return col
|
return col
|
||||||
|
|
||||||
# give left-over space from rounding to last column to get to 100%
|
# give left-over space from rounding to last column to get to 100%
|
||||||
roundingLeftOver = @el.width() - @getHeaderWidths headers
|
roundingLeftOver = availableWidth - @getHeaderWidths headers
|
||||||
# but only if there is something left over (will get negative when there are too many columns for each column to stay in their min width)
|
# but only if there is something left over (will get negative when there are too many columns for each column to stay in their min width)
|
||||||
if roundingLeftOver > 0
|
if roundingLeftOver > 0
|
||||||
headers[headers.length - 1].width = parseInt(headers[headers.length - 1].width, 10) + roundingLeftOver + "px"
|
headers[headers.length - 1].width = parseInt(headers[headers.length - 1].width, 10) + roundingLeftOver + "px"
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
<% for item, i in @header: %>
|
<% for item, i in @header: %>
|
||||||
<th class="<%= " #{ item.className }" if item.className %><%= " align-#{ item.align }" if item.align %>" style="width:<%= item.width %>" data-column-key="<%= item.name %>">
|
<th class="<%= " #{ item.className }" if item.className %><%= " align-#{ item.align }" if item.align %>" style="width:<%= item.width %>" data-column-key="<%= item.name %>">
|
||||||
<div <% if @table_id: %>class="table-column-head js-sort"<% end %>>
|
<div class="table-column-head<%= ' js-sort' if @table_id %>">
|
||||||
<div class="table-column-title">
|
<div class="table-column-title">
|
||||||
<%- @T( item.display ) %>
|
<%- @T( item.display ) %>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue