The Once and Future Grid

40

Transcript of The Once and Future Grid

Page 1: The Once and Future Grid
Page 2: The Once and Future Grid

Don GriffinDirector of Engineering, Sencha

@dongryphon

Page 3: The Once and Future Grid

The Onceand

Future Grid

Page 4: The Once and Future Grid

Goals

Building BlocksMapping ConceptsBring It Together

Page 5: The Once and Future Grid

Modern Grid

Architectural Focus for 6.0

Page 6: The Once and Future Grid

Modern Grid Architecture

Multi-Device InputCore Data

DOM ScrollerData Binding

Page 7: The Once and Future Grid

The Grid That Was…

XTemplates + cell renderers

(simple DOM replacement)

Page 8: The Once and Future Grid

The Grid That Was…

But…

DOM is SLOW

Page 9: The Once and Future Grid

The Grid That Is…

XTemplates + cell renderers + cell updaters

+ minimal re-render+ minimal DOM copy

+ buffered view updates+ field dependencies

Page 10: The Once and Future Grid

The Grid That Is…

An Optimization Challenge

Page 11: The Once and Future Grid

Renderers

{xtype:  'grid',

columns:  [{renderer:  function  (value,  meta,  rec)  {

return  rec.get('firstName')  +  '  '  +rec.get('lastName');

}}]

}

Page 12: The Once and Future Grid

The Grid That Is…

“What needs updating?”

Page 13: The Once and Future Grid

Field Dependency

{extend:  'Ext.data.Model',

fields:  [...,  {name:  'fullName',

convert:  function  (value,  rec)  {return  rec.data.firstName +  '  '  +

rec.data.lastName;},depends:  ['firstName',  'lastName']

}]}

Page 14: The Once and Future Grid

Field Dependency

{extend:  'Ext.data.Model',

fields:  [...,  {name:  'fullName',

calculate:  function  (data)  {return  data.firstName +  '  '  +

data.lastName;}

}]

}

Page 15: The Once and Future Grid

The Grid That Will Be…

Ext.List+ Configs

+ Data binding

Also Is…

Page 16: The Once and Future Grid

Where’s All The Magic Gone?

XTemplates + cell renderers

Cell updatersMinimal re-renderMinimal DOM copy

Buffered view updatesField dependencies

Ext.ListExt.grid.Row

Ext.grid.cell.*

Configs

Data binding

Page 17: The Once and Future Grid

Config Mojo

Ext.define('Ext.Widget',  {

config:  {cls:  null,...

},...

updateCls:  function  (cls,  oldCls)  {this.element.replaceCls(oldCls,  cls);

}});

getClssetCls

Page 18: The Once and Future Grid

The Standard Setter

setCls:  function  (value)  {var oldValue =  this._cls;

if  (this.applyCls)  {value  =  this.applyCls(value,  oldValue);

}if  (value  !==  this._cls)  {

this._cls =  value;if  (this.updateCls)  {

this.updateCls(value,  oldValue);

}}

}

Transformvalues

Manageside-effects

Page 19: The Once and Future Grid

Rows

Page 20: The Once and Future Grid

Grid extends ListExt.define('Ext.grid.Grid',  {

extend:  'Ext.List',xtype:  'grid',

config:  {defaultType:  'gridrow',infinite:  true

}});

Creates anExt.grid.Row

to display records

Page 21: The Once and Future Grid

Rows Are Containers of Cells

Page 22: The Once and Future Grid

Not exactly…

Page 23: The Once and Future Grid

Row extends Component

Ext.define('Ext.grid.Row',  {extend:  'Ext.Component',xtype:  'gridrow',

...});

Page 24: The Once and Future Grid

Rows Are Cell Containers

Page 25: The Once and Future Grid

add() and remove() - Noadd and remove events - No

Hierarchy – YesViewModels - Yes

Page 26: The Once and Future Grid

Row

Grid is a List of Rows

Row

Row

Row

Row

Row

VisibleSpares

Page 27: The Once and Future Grid

Grid is a List of Rows

Row

Row

Row

Rowsc

roll

[0]

[1]

[2]

[3]

[4]

setRecord(rec[4])

Page 28: The Once and Future Grid

updateRecord

Ext.define('Ext.grid.Row',  {...

updateRecord:  function  (rec)  {var vm =  this.getViewModel();if  (vm)  {

vm.set('record',  rec);}

}});

Page 29: The Once and Future Grid

Styling Rows

Page 30: The Once and Future Grid

Classic

items:  [{xtype:  'grid',viewConfig:  {

getRowClass:  function  (rec)  {return  rec.get("valid")  ?  "row-­‐valid"  :  "row-­‐error";

}}

}

Page 31: The Once and Future Grid

Modernitems:  [{

xtype:  'grid',itemConfig:  {

cls:  'row-­‐class',bind:  {

cls:  '{rowClsFormula}'},viewModel:  {

type:  'row-­‐model'}

}

Configures eachExt.grid.Row

Page 32: The Once and Future Grid

Cells

Page 33: The Once and Future Grid

columnsdrive cell

creation and order

Page 34: The Once and Future Grid

Columnsitems:  [{

xtype:  'grid',columns:  [{

//  xtype:  'column',text:  'Heading',cell:  {

//  xtype:  'gridcell',cls:  'mycell'

}}]

CellConfiguration

Page 35: The Once and Future Grid

ai

Grid Columns

bi ci

A B C

rows[i]

headerxtype:  'grid',columns:  [{

text:  '...',cell:  {...}

}]

Page 36: The Once and Future Grid

Base

Text Boolean

Cell

Date

NumberWidget

Cell Classes

Page 37: The Once and Future Grid

Widgets in Cellsitems:  [{

xtype:  'grid',columns:  [{

cell:  {xtype:  'widgetcell',widget:  {

xtype:  'button',bind:  '{record.name}'

}}

}]

WidgetConfiguration

Page 38: The Once and Future Grid

Ext.grid.plugin.*

EditableMultiSelectionPagingToolbarSummaryRowViewOptions

ColumnResizing

Page 39: The Once and Future Grid

https://fiddle.sencha.com/#fiddle/qmn

Demo

Page 40: The Once and Future Grid

Q & A

@dongryphon