Constructor
new CollectionComponent(dataObjectopt, optionsopt)
Parameters:
Name |
Type |
Attributes |
Default |
Description |
dataObject |
DataObject
|
<optional>
|
null
|
|
options |
Object
|
<optional>
|
{}
|
Properties
Name |
Type |
Attributes |
Default |
Description |
itemComponent |
Component
|
<optional>
|
DefaultItemComponent
|
a Component class used to render each item in this list |
itemOptions |
Object
|
<optional>
|
|
a set of options to pass to each item Component |
onClick |
CollectionComponent~onClick
|
<optional>
|
|
a function to call with the dataObject whose item Component is clicked |
|
- Source:
- To Do:
-
- Add rearrangement via drag and drop
- Add pagination support once DataCollection supports it
Examples
Use the DefaultItemComponent
const myCollection = new DataCollection(...snip...)
const collectionComponent = new CollectionComponent(myCollection)
Use a custom item Component
const myCollection = new DataCollection(...snip...)
class CustomItemComponent extends Component {
constructor(dataObject=null, options={}) {
// Set up your item UI here
}
}
const collectionComponent = new CollectionComponent(myCollection, {
itemComponent: CustomItemComponent, // the class, not an instance
itemOptions: { someKey: 'someValue' } // passed as options to item component constructors
})
Responding to clicks on items
const myCollection = new DataCollection(...snip...)
const collectionComponent = new CollectionComponent(myCollection, {
onClick: (dataObject) => {
// Do something with the DataObject (probably a DataModel) whose item has been clicked
}
})
Call this to change whether item Components are show or hidden based on the result of a function.
A common pattern is to listen to Collection events like fetched or reset and then re-run a filter.