2016-03-16 13:30:39 +13:00
|
|
|
import React from 'react';
|
2016-03-30 16:38:34 +13:00
|
|
|
import SilverStripeComponent from 'silverstripe-component';
|
2016-03-16 13:30:39 +13:00
|
|
|
|
2016-03-18 14:42:45 +13:00
|
|
|
class GridFieldTableComponent extends SilverStripeComponent {
|
2016-03-16 13:30:39 +13:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2016-03-18 14:42:45 +13:00
|
|
|
<ul className='grid-field-table-component [ list-group ]'>
|
2016-03-16 13:30:39 +13:00
|
|
|
{this.generateHeader()}
|
2016-03-18 14:42:45 +13:00
|
|
|
{this.generateRows()}
|
|
|
|
</ul>
|
2016-03-16 13:30:39 +13:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the header component.
|
|
|
|
*
|
|
|
|
* Uses the header component passed via the `header` prop if it exists.
|
|
|
|
* Otherwise generates a header from the `data` prop.
|
|
|
|
*
|
|
|
|
* @return object|null
|
|
|
|
*/
|
|
|
|
generateHeader() {
|
|
|
|
if (typeof this.props.header !== 'undefined') {
|
|
|
|
return this.props.header;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof this.props.data !== 'undefined') {
|
|
|
|
// TODO: Generate the header.
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the table rows.
|
|
|
|
*
|
|
|
|
* Uses the components passed via the `rows` props if it exists.
|
|
|
|
* Otherwise generates rows from the `data` prop.
|
|
|
|
*
|
|
|
|
* @return object|null
|
|
|
|
*/
|
|
|
|
generateRows() {
|
|
|
|
if (typeof this.props.rows !== 'undefined') {
|
|
|
|
return this.props.rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof this.props.data !== 'undefined') {
|
|
|
|
// TODO: Generate the rows.
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-18 14:42:45 +13:00
|
|
|
GridFieldTableComponent.propTypes = {
|
2016-03-16 13:30:39 +13:00
|
|
|
data: React.PropTypes.object,
|
|
|
|
header: React.PropTypes.object,
|
|
|
|
rows: React.PropTypes.array
|
|
|
|
};
|
|
|
|
|
2016-03-18 14:42:45 +13:00
|
|
|
export default GridFieldTableComponent;
|