Skip to content

Instantly share code, notes, and snippets.

@lsmith
Created November 10, 2011 21:51
Show Gist options
  • Save lsmith/1356355 to your computer and use it in GitHub Desktop.
Save lsmith/1356355 to your computer and use it in GitHub Desktop.

DataTable design overview

These are my early thoughts on how to structure DataTable in 3.5.0. Feedback is welcome in the comments.

Instantiable classes out of the box

new Y.DataTable({...});
new Y.DataTable.Base({...});

Class generation

Y.DataTable.Base = Y.Base.create('datatable', Y.Widget, [Y.DataTable.Core]);
Y.DataTable = Y.mix(
    Y.Base.create('datatable', Y.DataTable.Base, []),
    Y.DataTable, true);

Class extensions CAN (if non-invasive by default)

Y.Base.mix(Y.DataTable, [ Y.DataTable.Sortable ]);

Primary configuration

new Y.DataTable({
    data: [{ ... }, { ... }, ... ]
    data: modelList
    data: {
        source: url, function, xml
        type: 'json'
        schema: { ... }        
    }

    columns: (optional) [ key, key, { key: key, config: stuff, ... }, ... ]

    recordType: (optional) ModelClass

    headerView: (optional) ViewClass
    bodyView: (optional) ViewClass
    footerView: (optional) ViewClass

    summary: (optional) 'string'
    caption: (optional) 'string'
});

Instance structure

instance
    .data = modelListInstance

    .head = viewInstance
    .body = viewInstance
    .foot = viewInstance

Component classes

  • Y.DataTable.Core

    Everything added to Y.Widget to make DataTable.Base

  • Y.DataTable.HeaderView

  • Y.DataTable.BodyView

  • Y.DataTable.FooterView

    Used by DataTable(.Base) to render the table contents.

    Referenced via configuration, not composition.

  • Y.DataTable.Source

    Optional class extension.

    Adds support data config to generate ML with DataSource load.

  • Y.DataTable.Scrollable

    Optional class extension.

    Adds support for scrolling table. May be used to create a third instantiable class.

  • Y.DataTable.ScrollingBodyView

    Used in place of DataTable.BodyView to render the scrolling table. May not be necessary?

  • Y.DataTable.Sortable

    Adds support for sorting headers and sortable config.

Render lifecycle

instance.render(...)

  1. build <table> (markup only or off DOM node?)
  2. instantiate header, body, footer views passing
    1. the DT instance
    2. the created table?
    3. the data ModelList?
  3. call each view's render()

Logic for reacting to user input is moved to the View classes

Concern: string based rendering would have viewX.render() return a string or populate a property, but it has requirements of the DT renderer

Load lifecycle

instance.load(...)

Pass through to this.data.load(...). Let the ModelList be responsible for data interaction.

Default Model generation

  • No ModelList is provided in data configuration AND
  • No recordType is provided in configuration
  1. Use the first item in the data array to build ATTRS and Y.Base.create(...)
  2. If data is empty, use columns?
@lsmith
Copy link
Author

lsmith commented Jan 19, 2012

@stlsmiths

re: 2 - I'm not planning on supporting a configuration for it, but you should be able to call table.sort('clientId') to resort by insertion order. That should DWYW.

re: 3 - This was a concession for the sake of time. It may come back to bite me in the ass, but I abandoned the notion of having the views generate their own relative containers (see https://gist.github.com/1356355#gistcomment-62759) because it was more convenient to have the important Nodes as properties on the DT instance (e.g. table._theadNode) but I didn't want to have to deal with a this._tbodies collection when in the majority of cases, there would be only one. It simplified all code that dealt with the data rows to have a single Node property for the data container, and _tbodyNode matched _tfootNode and _theadNode. If a custom bodyView wants to render multiple <tbody>s, it can hack the addition of more somewhere in the table's rendering lifecycle. Ugly, I admit.

re: 5 - row insertion point is managed by ModelList's sorting algo, but addColumn does accept an insertion index. - http://lsmith.github.com/yui3-gallery/api/classes/DataTable.html#method_addColumn

re: 6 - Yes. Party at my house :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment