@progress/kendo-react-grid
Version:
KendoReact Grid package
94 lines • 4.22 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
import * as React from 'react';
import { GridFilterCell } from '../cells/GridFilterCell';
/**
*
* @hidden
*/
var FilterRow = /** @class */ (function (_super) {
__extends(FilterRow, _super);
function FilterRow() {
return _super !== null && _super.apply(this, arguments) || this;
}
FilterRow.prototype.headerCellClassName = function (field) {
if (this.props.sort &&
this.props.sort.filter(function (descriptor) { return descriptor.field === field; }).length > 0) {
return 'k-sorted';
}
return '';
};
FilterRow.prototype.setFilter = function (value, operator, field, e) {
if (!this.props.filterChange) {
return;
}
var filters = [];
if (value !== '' && value !== null || operator !== '') {
filters.push({
field: field,
operator: operator,
value: value
});
}
if (this.props.filter && this.props.filter.filters) {
var oldFilters = this.props.filter.filters || [];
oldFilters.forEach(function (filter) {
var descriptor = filter;
if (descriptor && descriptor.field !== field) {
filters.push(descriptor);
}
});
}
this.props.filterChange(filters.length > 0 ? { logic: 'and', filters: filters } : null, e);
};
FilterRow.prototype.render = function () {
var _this = this;
var oldFilters = this.props.filter && this.props.filter.filters || [];
var activeFilterValueFor = function (field, defaultValue) {
if (defaultValue === void 0) { defaultValue = null; }
var found = oldFilters.filter(function (filter) { return filter.field === field; })[0];
return found ? found.value : defaultValue;
};
var activeOperatorFor = function (field) {
var found = oldFilters.filter(function (filter) { return filter.field === field; })[0];
return found ? found.operator : null;
};
var serviceIndex = 0, index = -1;
var filterCells = this.props.columns.filter(function (c) { return c.children.length === 0; })
.map(function (column) {
var filterType = column.filter === undefined ? 'text' : column.filter;
var filterCellProps = column.filterable && {
render: _this.props.cellRender,
field: column.field,
value: activeFilterValueFor(column.field, filterType === 'text' ? '' : null),
operator: activeOperatorFor(column.field),
filterType: filterType,
onChange: function (e) { _this.setFilter(e.value, e.operator, column.field, e.syntheticEvent); }
};
var key = (column.declarationIndex >= 0) ? ++index : --serviceIndex;
return (React.createElement("th", { key: key, className: _this.headerCellClassName(column.field) }, filterCellProps && (column.filterCell ?
React.createElement(column.filterCell, __assign({}, filterCellProps)) :
React.createElement(GridFilterCell, __assign({}, filterCellProps)))));
});
return React.createElement("tr", { className: "k-filter-row" }, filterCells);
};
return FilterRow;
}(React.Component));
export { FilterRow };
//# sourceMappingURL=FilterRow.js.map