These are my early thoughts on how to structure DataTable in 3.5.0. Feedback is welcome in the comments.
new Y.DataTable({...});
new Y.DataTable.Base({...});
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 ]);
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
.data = modelListInstance
.head = viewInstance
.body = viewInstance
.foot = viewInstance
-
Y.DataTable.CoreEverything added to Y.Widget to make DataTable.Base
-
Y.DataTable.HeaderView -
Y.DataTable.BodyView -
Y.DataTable.FooterViewUsed by DataTable(.Base) to render the table contents.
Referenced via configuration, not composition.
-
Y.DataTable.SourceOptional class extension.
Adds support
dataconfig to generate ML with DataSource load. -
Y.DataTable.ScrollableOptional class extension.
Adds support for scrolling table. May be used to create a third instantiable class.
-
Y.DataTable.ScrollingBodyViewUsed in place of DataTable.BodyView to render the scrolling table. May not be necessary?
-
Y.DataTable.SortableAdds support for sorting headers and sortable config.
instance.render(...)
- build <table> (markup only or off DOM node?)
- instantiate header, body, footer views passing
- the DT instance
- the created table?
- the
dataModelList?
- 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
instance.load(...)
Pass through to this.data.load(...). Let the ModelList be responsible for data interaction.
- No ModelList is provided in
dataconfiguration AND - No
recordTypeis provided in configuration
- Use the first item in the data array to build ATTRS and Y.Base.create(...)
- If data is empty, use columns?
@ericf, @mosen - The row id == clientId came out because I worry that the clientId won't be unique across DataTable instances or YUI instances.
@sdesai - so far, I've seen a need for the body and header views to have a
getClassNamemethod (that I cribbed from Widget) and the body view has agetCellandgetRowmethod which the Core implementation relays the arguments to. Since it is up to the view to decide how to create the rows and cells, it should be up to the view to decide how to fetch them.The
getClassNamebeing on the views is mainly to keep the views decoupled from DataTable. I pass the_cssPrefixto the views as acssPrefixconfig property. The views'initializerthen takes the config and, if set, sets the instance's_cssPrefix, shadowing the default_cssPrefixfrom the view's prototype. This allows the view instances to use their owngetClassNameto generate classes appropriate for the DT or for another consumer, falling back to classes built from the prototype_cssPrefix. I can either keep you updated here on in the pull request (yui/yui3#63).