new Customers()
React component consuming a Customer Data Entity collection to feed a grid.
React component consuming a Customer Data Entity collection to feed a grid
- Source:
Extends
- React.Component
Members
-
entity
Entity name which this component represents to.
-
Entity name which this component represents to
- Source:
-
foundation
access to foundation instance.
-
access to foundation instance
- Source:
-
onAddDocEventListener
listen to add Customer Data Entity change event on Data API.
-
listen to add Customer Data Entity change event on Data API
- Source:
-
onDeleteDocEventListener
listen to delete Customer Data Entity change event on Data API.
-
listen to delete Customer Data Entity change event on Data API
- Source:
-
onEditDocEventListener
listen to edit Customer Data Entity change event on Data API.
-
listen to edit Customer Data Entity change event on Data API
- Source:
-
pagination
default pagination to list data.
-
default pagination to list data
- Source:
-
state
component state.
-
component state
- Source:
Methods
-
<async, static> componentDidMount()
Called immediately after a component is mounted. Setting state here will trigger re-rendering.
-
Once component is monted we are now ready to start listen to changes on Customer data entity and get a list of customer in database to fill out the state.customers
- Source:
Example
componentDidMount() { const { Customer } = this.foundation.data this.onAddDocEventListener = Customer.on( 'add', handlerOnAddDocEventListener.bind(this) ) this.onEditDocEventListener = Customer.on( 'edit', handlerOnEditDocEventListener.bind(this) ) this.onDeleteDocEventListener = Customer.on( 'delete', handlerOnDeleteDocEventListener.bind(this) ) const { error, data } = await Customer.find({}, { ...this.pagination }) if (!error) { this.setState({ customers: customers.data }) } }
-
<static> componentWillUnmount()
Called immediately before a component is destroyed. Perform any necessary cleanup in this method, such as cancelled network requests, or cleaning up any DOM elements created in componentDidMount.
-
lets stop listen to Customer Data State Change Events
- Source:
Example
componentWillUnmount() { const { Customer } = this.foundation.data Customer.stopListenTo(this.onAddDocEventListener) Customer.stopListenTo(this.onEditDocEventListener) Customer.stopListenTo(this.onDeleteDocEventListener) }
-
<static> handleDeleteCustomer(event, __id)
Event handler that Deletes a customer
-
Once component is monted we are now ready to start listen to changes on Customer data entity and get a list of customer in database to fill out the state.customers
Parameters:
Name Type Description event
event The HTML event triggered on User interation __id
number The primaryKey value of the record willing to be deleted - Source:
Example
handleDeleteCustomer(e, ___id) { const { Customer } = this.foundation.data e.preventDefault() swal({ title: 'Are you sure?', text: 'Once deleted, you will not be able to recover this!', icon: 'warning', buttons: true, dangerMode: true }).then(async (willDelete) => { if (willDelete) { const r = await Customer.delete(___id) if (r.error) { swal('Database error', e.error.message, 'error') return } swal('Poof! The customer has been deleted!', { icon: 'success' }) return <Redirect to = '/dashboard' / > } else { swal('The Customer is safe!') } }) } // <a color='primary' href='#' onClick={e => this.handleDeleteCustomer(e, doc.__id)}>[delete]</a>
-
<async, static> render()
Component render function.
-
Renders a grid of Customers
- Source: