Skip to content

Commit

Permalink
Filter string is tokenized and ALL'd
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Gilliard committed Dec 7, 2016
1 parent 8942eba commit ebdbc21
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/reagent_data_table/core.cljs
Expand Up @@ -2,14 +2,27 @@
(:require [reagent.core :as reagent]
[clojure.string :as s]))

(defn- filter-tokens

"Splits a string of filter text into tokens"

[s]
(-> s
(s/split #"\s+")
(->>
(remove empty?))))

(defn- filter-row

"Predicate fn for deciding whether to show a row when filtering is being applied"
"Predicate fn for deciding whether to show a row when filtering is being applied. All filters must match somewhere
in a row for it to be shown"

[s filter-cols row-map]
(let [filterables ((apply juxt filter-cols) row-map)]
(some identity
(map #(s/index-of (s/upper-case (str %)) (s/upper-case (str s))) filterables))))
(every? identity ;; every filter must match
(for [filter (filter-tokens s)]
(some identity ;; some column
(for [col ((apply juxt filter-cols) row-map)]
(s/index-of (s/upper-case (str col)) (s/upper-case (str filter))))))))

(defn- sort-indicator

Expand Down

0 comments on commit ebdbc21

Please sign in to comment.