meraproject/lib/js/bws/react/table/thead.js

115 lines
2.7 KiB
JavaScript
Raw Permalink Normal View History

var Thead;
import autoBind from 'react-autobind';
import Checkbox from "../form/checkbox";
export default window.Thead = Thead = class Thead extends React.Component {
constructor(props) {
var ref;
super(props);
this.state = {
columns: (ref = props.columns) != null ? ref : [],
hide_thead: props.hide_thead === true,
sortable: props.sortable === true
}; //this.renderTh = this.renderTh.bind(this)
autoBind(this);
this.filter_inputs = {};
this.timeout = null;
}
setSelected(x) {
return this.setState({
selected: x === true
});
}
onSelect(x) {
var base;
return typeof (base = this.props).onSelect === "function" ? base.onSelect(x) : void 0;
}
getFilterData() {
var i, res, v, value;
res = {};
for (i in this.filter_inputs) {
v = this.filter_inputs[i];
value = v.value;
if (value !== "") {
res[i] = v.value;
}
}
return res;
}
prepareToFilter() {
clearTimeout(this.timeout);
return this.timeout = setTimeout(this.filter, 350);
}
filter() {
var values;
values = this.getFilterData();
return this.props.onSetFilter(values);
}
renderFilter(item) {
var _this = this;
var input, value;
input = null;
value = item.filter;
switch (item.type) {
case 2:
input = /*#__PURE__*/React.createElement("input", {
class: "i c-100",
onKeyUp: this.prepareToFilter,
placeholder: item.name,
ref: function (i) {
return _this.filter_inputs[item.id] = i;
},
defaultValue: value
});
}
return /*#__PURE__*/React.createElement("th", null, input);
}
renderTh(item) {
return /*#__PURE__*/React.createElement("th", null, /*#__PURE__*/React.createElement("div", {
className: "text"
}, item.name));
}
render() {
var columns, hide_thead, isFilter, sortable;
({
columns,
hide_thead,
sortable
} = this.state);
isFilter = true;
if (sortable) {
isFilter = false;
}
if (hide_thead) {
return null;
}
return /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement("tr", null, sortable ? /*#__PURE__*/React.createElement("th", {
class: "c-1"
}) : null, /*#__PURE__*/React.createElement("th", {
class: "c-1"
}, /*#__PURE__*/React.createElement(Checkbox, {
checked: this.state.selected,
onChange: this.onSelect
})), columns.map(this.renderTh)), isFilter ? /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("th", null, "\xA0"), columns.map(this.renderFilter)) : null);
}
};
//# sourceMappingURL=thead.js.map