Skip to content

Commit

Permalink
New column resizing behavior and modes.
Browse files Browse the repository at this point in the history
Splits resizing behavior into two modes (standard and fluid), configurable via:

columnMode: 'standard/fluid'

In standard mode, columns push and pull their neighbors; resizing a column will
change only that column's width.

In fluid mode, columns steal width from their neighbors when resized.

Column configuration options have been made more effective and consistent:
minWidth/maxWidth now work reliably, and isResizable/isSortable/canAutoResize
can be configured to get a wide range of behaviors out of Ember Table. Width
can be persisted via the savedWidth property.

Finally, adds a "configurable column demo" that makes it easy to play with the
new configurations to see what they do or find a behavior that will work for
different use cases.
  • Loading branch information
Alex Zirbel committed Dec 5, 2014
1 parent a8c0c59 commit 3dd7254
Show file tree
Hide file tree
Showing 32 changed files with 772 additions and 428 deletions.
18 changes: 9 additions & 9 deletions app/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ window.App = Ember.Application.create
require 'build/app/data/data'

# Controllers
require 'build/app/controllers/overview'
require 'build/app/controllers/simple'
require 'build/app/controllers/ajax'
require 'build/app/controllers/bars'
require 'build/app/controllers/dynamic_bars'
require 'build/app/controllers/editable'
require 'build/app/controllers/treetable'
require 'build/app/controllers/financial'
require 'build/app/controllers/fluid'
require 'build/app/controllers/horizon'
require 'build/app/controllers/overview'
require 'build/app/controllers/simple'
require 'build/app/controllers/editable'
require 'build/app/controllers/sparkline'
require 'build/app/controllers/treetable'
require 'build/app/controllers/horizon'
require 'build/app/controllers/configurable-columns'

# Views
require 'build/app/views/mixins'
require 'build/app/views/ember_table'
require 'build/app/views/ember_table/ajax'
require 'build/app/views/ember_table/bars'
require 'build/app/views/ember_table/editable'
require 'build/app/views/ember_table/financial'
require 'build/app/views/ember_table/horizon'
require 'build/app/views/ember_table/sparkline'
require 'build/app/views/ember_table/treetable'
require 'build/app/views/ember_table/editable'
require 'build/app/views/ember_table/sparkline'
require 'build/app/views/ember_table/horizon'

# Router
require 'build/app/router'
Expand Down
76 changes: 75 additions & 1 deletion app/assets/css/app.less
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ pre {
.example-container {
position: relative;
padding: 45px 15px 15px;
// background-color: #f8f8f8;
border: 1px solid #eee;
}

Expand All @@ -604,6 +603,81 @@ pre {
margin: 10px 0;
}

/* Configuration Container
-------------------------------------------------- */
.configuration-container {
position: relative;
margin-bottom: 20px;
padding: 15px;
background-color: #f8f8f8;
border: 1px solid #ddd;

.title-text {
top: 15px;
left: 15px;
font-size: 12px;
font-weight: normal;
font-family: 'Univers Next W01 Medium';
letter-spacing: 1px;
color: #555;
text-transform: uppercase;
margin-bottom: 10px;
}

.text-input {
width: 50px;
border: none;
background-color: transparent;
padding: 0;
}

.at-limit {
background-color: #f5e0e0;
}

.checkbox-column {
width: 100px;
}

.width-column {
width: 115px;
}

.checkbox-cell {
padding: 0;
}

.checkbox-input {
height: 100%;
width: 100%;
margin: 0 0 0 6px;
position: relative; // Needed for z-index
z-index: 2; // Show up on top of .fluid-mode-text
}

.table-options-footer {
position: relative;
height: 30px;
}

.refresh-btn {
position: absolute;
right: 0;
bottom: 0;
padding: 6px 10px;
margin-top: 15px;
z-index: 3;
}

.fluid-mode-text {
position: absolute;
line-height: 30px;
left: 32px;
top: 1px;
z-index: 1;
}
}

/* Index Page
============================================================================= */

Expand Down
13 changes: 8 additions & 5 deletions app/assets/css/ember-table-page.less
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@

.ember-table-example-container {
height: 500px;
// border: 1px solid #ddd;
}

.ember-table-example-container-small {
height: 150px;
}

.ember-table-options {
Expand Down Expand Up @@ -138,7 +141,7 @@
content: "\f005" !important;
}

/* Ember Tabel Bar Chart Cells
/* Ember Table Bar Chart Cells
-------------------------------------------------- */
.bar-cell {
height: 29px !important;
Expand All @@ -161,8 +164,8 @@
background-color: #FD7400;
}

/* Ajax cells */

/* Ajax cells
-------------------------------------------------- */
.img-table-cell img {
margin: 2px 20px 2px 20px;
}
}
4 changes: 2 additions & 2 deletions app/controllers/ajax.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ App.EmberTableAjaxController = Ember.Controller.extend

columns: Ember.computed ->
avatar = Ember.Table.ColumnDefinition.create
columnWidth: 80
savedWidth: 80
headerCellName: 'avatar'
tableCellViewClass: 'App.EmberTableAjaxImageTableCell'
contentPath: 'avatar'
columnNames = ['login', 'type', 'createdAt']
columns = columnNames.map (key, index) ->
Ember.Table.ColumnDefinition.create
columnWidth: 150
savedWidth: 150
headerCellName: key.w()
contentPath: key
columns.unshift avatar
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/bars.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ App.EmberTableBarsController = Ember.Controller.extend
columns: Ember.computed ->
colors = ['blue', 'teal', 'green', 'yellow', 'orange']
column1 = Ember.Table.ColumnDefinition.create
columnWidth: 50
savedWidth: 50
headerCellName: 'Name'
contentPath: 'key'
columns = colors.map (color, index) ->
Expand Down
113 changes: 113 additions & 0 deletions app/controllers/configurable-columns.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
App.EmberTableConfigurableColumnsController = Ember.Controller.extend
numRows: 100

isFluid: no
columnMode: Ember.computed ->
if @get('isFluid') then 'fluid' else 'standard'
.property 'isFluid'

showTable: yes

columns: Ember.computed ->
dateColumn = App.ConfigurableColumnDefinition.create
textAlign: 'text-align-left'
headerCellName: 'Date'
minWidth: 150
getCellContent: (row) -> row.get('date').toDateString();
openColumn = App.ConfigurableColumnDefinition.create
headerCellName: 'Open'
getCellContent: (row) -> row.get('open').toFixed(2)
highColumn = App.ConfigurableColumnDefinition.create
headerCellName: 'High'
getCellContent: (row) -> row.get('high').toFixed(2)
lowColumn = App.ConfigurableColumnDefinition.create
headerCellName: 'Low'
getCellContent: (row) -> row.get('low').toFixed(2)
closeColumn = App.ConfigurableColumnDefinition.create
headerCellName: 'Close'
getCellContent: (row) -> row.get('close').toFixed(2)
[dateColumn, openColumn, highColumn, lowColumn, closeColumn]

content: Ember.computed ->
[0...@get('numRows')].map (index) ->
date = new Date()
date.setDate(date.getDate() + index)
date: date
open: Math.random() * 100 - 50
high: Math.random() * 100 - 50
low: Math.random() * 100 - 50
close: Math.random() * 100 - 50
volume: Math.random() * 1000000
.property 'numRows'

# We bind the container width to a `parentWidth` property on the
# `ConfigurableTableComponent`. Then we extend the table to force it to
# handle resizes whenever the `parentWidth` changes. This is a hack - the
# table should take care of resizing to available width on its own, but for
# now we need this to make the demo work.
demoTableWidth: undefined
updateDemoTableWidth: (newWidth) ->
@set 'demoTableWidth', newWidth

actions:
# Pulls the table out and back into the DOM
refreshTable: ->
@set 'showTable', no
Ember.run.next =>
@set 'showTable', yes

# We extend Ember.Table.ColumnDefinition for two reasons: to use custom
# getters/setters for savedWidth/minWidth/maxWidth so that they can be set via
# the configuration container, and to add properties which can be used for
# formatting.
App.ConfigurableColumnDefinition = Ember.Table.ColumnDefinition.extend
savedWidth: undefined
savedWidthValue: Ember.computed (key, value) ->
if arguments.length is 1
return @get('savedWidth')
else
@set('savedWidth', parseInt(value))
return @get('savedWidth')
.property 'savedWidth'

minWidthValue: Ember.computed (key, value) ->
if arguments.length is 1
return @get('minWidth')
else
@set('minWidth', parseInt(value))
return @get('minWidth')
.property 'minWidth'

atMinWidth: Ember.computed ->
@get('width') is @get('minWidth')
.property 'width', 'minWidth'

atMaxWidth: Ember.computed ->
@get('width') is @get('maxWidth')
.property 'width', 'maxWidth'

maxWidth: undefined
maxWidthValue: Ember.computed (key, value) ->
if arguments.length is 1
return @get('maxWidth')
else
@set('maxWidth', parseInt(value))
return @get('maxWidth')
.property 'maxWidth'

headerCellNameLowerCase: Ember.computed ->
@get('headerCellName').toLowerCase()
.property 'headerCellName'

isDateCell: Ember.computed.equal 'headerCellName', 'Date'
textAlignIsDefault: Ember.computed.equal 'textAlign', 'text-align-right'
minWidthIsDefault: Ember.computed.equal 'minWidth', 25

# TODO(azirbel): We extend this to create a very hacky way of calling
# `@onResizeEnd` in the table, triggered by resizing the table's container. We
# only need to do this because the table currently does a bad job detecting
# when its width has changed.
App.ConfigurableTableComponent = Ember.Table.EmberTableComponent.extend
parentWidthObserver: Ember.observer( ->
@onResizeEnd()
, 'parentWidth')
4 changes: 2 additions & 2 deletions app/controllers/dynamic_bars.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ App.EmberTableDynamicBarsController = Ember.Controller.extend
, 1500

columns: Ember.computed ->
colors = ['blue', 'teal', 'green', 'yellow', 'orange']
colors = ['blue', 'teal', 'green', 'yellow', 'orange']
column1 = Ember.Table.ColumnDefinition.create
columnWidth: 50
savedWidth: 50
headerCellName: 'Name'
contentPath: 'key'
columns = colors.map (color, index) ->
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/editable.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ App.EmberTableEditableController = Ember.Controller.extend
columns: Ember.computed ->
columnNames = ['open', 'close']
dateColumn = Ember.Table.ColumnDefinition.create
columnWidth: 100
savedWidth: 100
headerCellName: 'Date'
tableCellViewClass: 'App.DatePickerTableCell'
getCellContent: (row) -> row.get('date').toString('yyyy-MM-dd')
setCellContent: (row, value) -> row.set('date', value)
ratingColumn = Ember.Table.ColumnDefinition.create
columnWidth: 150
savedWidth: 150
headerCellName: 'Analyst Rating'
tableCellViewClass: 'App.RatingTableCell'
contentPath: 'rating'
setCellContent: (row, value) -> row.set('rating', value)
columns= columnNames.map (key, index) ->
name = key.charAt(0).toUpperCase() + key.slice(1)
Ember.Table.ColumnDefinition.create
columnWidth: 100
savedWidth: 100
headerCellName: name
tableCellViewClass: 'App.EditableTableCell'
getCellContent: (row) -> row.get(key).toFixed(2)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/financial.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ App.FinancialTableComponent = Ember.Table.EmberTableComponent.extend
name = groupingFactors.getEach('display_name').join ''
Ember.Table.ColumnDefinition.create
headerCellName: name
columnWidth: 400
savedWidth: 400
isTreeColumn: yes
isSortable: no
textAlign: 'text-align-left'
Expand Down
Loading

0 comments on commit 3dd7254

Please sign in to comment.