kea-react
Version:
Componentes comunes de react
38 lines (37 loc) • 1.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var botones_1 = require("../../botones");
var filtrarOrdenar_1 = require("../simpleGrid/filtrarOrdenar");
var selector_1 = require("../../selector");
function filter(item, data, string) {
if (data.valores == null)
return true;
if (data.valores.length == 0)
return true;
return data.valores.indexOf(string) != -1;
}
function FiltroValorUnicoComponent(props) {
var x = props.value || { valores: [] };
var items = getItems(props.items, props.column);
var titulo = props.titulo;
var label = React.createElement("span", null,
React.createElement(botones_1.Link, { iconClass: "fa fa-times", onClick: props.onQuitar }),
" ",
React.createElement("label", null, titulo));
return (React.createElement("div", null,
React.createElement(selector_1.MultiSelect, { value: x.valores || [], onChange: function (x) { return props.onChange({ valores: x }); }, items: items, label: label })));
}
/**Obtiene los valroes unicos de una columna */
function valoresUnicos(datos, column) {
var valores = datos.map(function (fila) { return fila.cell[column].string; });
var set = new Set(valores);
return Array.from(set).sort(function (a, b) { return filtrarOrdenar_1.compare(a, b); });
}
function getItems(datos, column) {
return valoresUnicos(datos, column).map(function (x) { return ({ value: x, label: x }); });
}
exports.filtro = {
component: FiltroValorUnicoComponent,
filter: function (item, data, string) { return filter(item, data, string); }
};