-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New column resizing behavior and modes.
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
Showing
32 changed files
with
772 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.