Created
July 7, 2014 13:47
-
-
Save dustingetz/018828c0754e0e73f8c8 to your computer and use it in GitHub Desktop.
Dismissible Grid - Dustin's version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([ | |
'underscore.mixed', 'react', 'wingspan-forms' | |
], function (_, React, Forms) { | |
'use strict'; | |
var SelectedRecipientsGrid = React.createClass({ | |
getDefaultProps: function () { | |
return { | |
dataSource: undefined, // the datasource as list of records | |
value: undefined, // the ids (projection of the datasource) | |
onChange: undefined, | |
height: undefined | |
}; | |
}, | |
render: function () { | |
// the selection value/onChange semantics are handled above the grid | |
return ( | |
Forms.KendoGrid({ | |
dataSource: this.props.dataSource, | |
height: this.props.height, | |
columns: [{ field: 'clientUserName' }, { field: '', width: 30, template: '<button class="buttonUnselect" id="#: clientUserId #"></button>' }] | |
}) | |
); | |
}, | |
componentDidMount: function () { | |
var $el = $(this.getDOMNode()); | |
$el.on('click', '.buttonUnselect', this.onButtonClick); | |
}, | |
componentWillUnmount: function () { | |
var $el = $(this.getDOMNode()); | |
$el.off('click', '.buttonUnselect', this.onButtonClick); | |
}, | |
onButtonClick: function (e) { | |
var idToBeRemoved = e.target.getAttribute('id'); | |
var nextValue = _.difference(this.props.value, [idToBeRemoved]); | |
this.props.onChange(nextValue); | |
} | |
}); | |
return SelectedRecipientsGrid; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment