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