gridjs
Version:
Advanced table plugin
3 lines (2 loc) • 2.79 kB
JavaScript
var t=require("gridjs");function e(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,s(t,e)}function s(t,e){return(s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var o=function(t){function s(){return t.apply(this,arguments)||this}e(s,t);var o=s.prototype;return o.getInitialState=function(){return{rowIds:[]}},o.handle=function(t,e){"CHECK"===t&&this.check(e.ROW_ID),"UNCHECK"===t&&this.uncheck(e.ROW_ID)},o.check=function(t){this.state.rowIds.indexOf(t)>-1||this.setState({rowIds:[t].concat(this.state.rowIds)})},o.uncheck=function(t){var e=this.state.rowIds.indexOf(t);if(-1!==e){var s=[].concat(this.state.rowIds);s.splice(e,1),this.setState({rowIds:s})}},s}(t.BaseStore),n=function(t){function s(){return t.apply(this,arguments)||this}e(s,t);var o=s.prototype;return o.check=function(t){this.dispatch("CHECK",{ROW_ID:t})},o.uncheck=function(t){this.dispatch("UNCHECK",{ROW_ID:t})},s}(t.BaseActions),i=function(s){function i(t,e){var i;if((i=s.call(this,t,e)||this).actions=void 0,i.store=void 0,i.storeUpdatedFn=void 0,i.isDataCell=function(t){return void 0!==t.row},i.getParentTR=function(){return i.base&&i.base.parentElement&&i.base.parentElement.parentElement},i.state={isChecked:!1},i.isDataCell(t)){if(t.store)i.store=t.store;else{var r=new o(i.config.dispatcher);i.store=r,t.plugin.props.store=r}i.actions=new n(i.config.dispatcher),i.storeUpdatedFn=i.storeUpdated.bind(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(i)),i.store.on("updated",i.storeUpdatedFn),t.cell.data&&i.check()}return i}e(i,s);var r=i.prototype;return r.componentWillUnmount=function(){this.store.off("updated",this.storeUpdatedFn)},r.componentDidMount=function(){this.store&&this.storeUpdated(this.store.state)},r.storeUpdated=function(t){var e=this.getParentTR();if(e){var s=t.rowIds.indexOf(this.props.id(this.props.row))>-1;this.setState({isChecked:s}),s?e.classList.add(this.props.selectedClassName):e.classList.remove(this.props.selectedClassName)}},r.check=function(){this.actions.check(this.props.id(this.props.row)),this.props.cell.update(!0)},r.uncheck=function(){this.actions.uncheck(this.props.id(this.props.row)),this.props.cell.update(!1)},r.toggle=function(){this.state.isChecked?this.uncheck():this.check()},r.render=function(){var e=this;return this.isDataCell(this.props)?t.h("input",{type:"checkbox",checked:this.state.isChecked,onChange:function(){return e.toggle()},className:this.props.checkboxClassName}):null},i}(t.PluginBaseComponent);i.defaultProps={selectedClassName:t.className("tr","selected"),checkboxClassName:t.className("checkbox")},exports.RowSelection=i,exports.RowSelectionActions=n,exports.RowSelectionStore=o;
//# sourceMappingURL=selection.js.map