doGlobalSearch() can be used to search a data frame given the search
string typed by the user into the global search box of a
datatable. doColumnSearch() does the same for a vector
given the search string typed into a column filter. These functions are used
internally by the default filter function passed to
dataTableAjax(), allowing you to replicate the search results
that server-side processing returns.
a vector, the type of which determines the expected
search_string format
a string that determines what to search for. The format depends on the type of input, matching what a user would type in the associated filter control.
a list of options used to control how searching character
values works. Supported options are regex, caseInsensitive
and (for global search)
smart.
a data frame
An integer vector of filtered row indices
The column filters section online for search string formats: https://rstudio.github.io/DT/
Accessing the search strings typed by a user in a Shiny app: https://rstudio.github.io/DT/shiny.html
doGlobalSearch(iris, "versi")
#> [1] 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
#> [20] 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#> [39] 89 90 91 92 93 94 95 96 97 98 99 100
doGlobalSearch(iris, "v.r.i", options = list(regex = TRUE))
#> [1] 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#> [19] 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
#> [37] 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
#> [55] 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
#> [73] 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
#> [91] 141 142 143 144 145 146 147 148 149 150
doColumnSearch(iris$Species, "[\"versicolor\"]")
#> [1] 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
#> [20] 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#> [39] 89 90 91 92 93 94 95 96 97 98 99 100
doColumnSearch(iris$Sepal.Length, "4 ... 5")
#> [1] 2 3 4 5 7 8 9 10 12 13 14 23 25 26 27 30 31 35 36
#> [20] 38 39 41 42 43 44 46 48 50 58 61 94 107