|
98 | 98 | ```
|
99 | 99 | </Option>
|
100 | 100 |
|
101 |
| - |
102 |
| -### Scope out global or resource searches |
103 |
| - |
104 |
| -You may want to perform different searches on the `global` search from the `resource` search. You may use the `params[:global]` flag to figure that out. |
105 |
| - |
106 |
| -```ruby{5-11} |
107 |
| -# app/avo/resources/order.rb |
108 |
| -class Avo::Resources::Order < Avo::BaseResource |
109 |
| - self.search = { |
110 |
| - query: -> { |
111 |
| - if params[:global] |
112 |
| - # Perform global search |
113 |
| - query.ransack(id_eq: q, m: "or").result(distinct: false) |
114 |
| - else |
115 |
| - # Perform resource search |
116 |
| - query.ransack(id_eq: q, details_cont: q, m: "or").result(distinct: false) |
117 |
| - end |
118 |
| - } |
119 |
| - } |
120 |
| -end |
121 |
| -``` |
122 |
| - |
123 | 101 | <Option name="`results_count`">
|
124 | 102 |
|
125 | 103 | By default, Avo displays 8 search results for each resource in the global search. You can change the number of results displayed by configuring the `search_results_count` option:
|
@@ -159,6 +137,58 @@ If you configure `results_count` by specifying it in the resource file then that
|
159 | 137 |
|
160 | 138 | </Option>
|
161 | 139 |
|
| 140 | +<Option name="`display_count`"> |
| 141 | + |
| 142 | +By default, Avo displays the search results count for each resource in the global search. Example: "Users (8 of 21)". You can avoid counting the number of results by configuring the `display_count` option |
| 143 | + |
| 144 | +This is useful if you have a custom search provider that doesn't return the number of results or if you want to avoid counting the number of results on large datasets. |
| 145 | + |
| 146 | +```ruby{4} |
| 147 | +# app/avo/resources/user.rb |
| 148 | +class Avo::Resources::User < Avo::BaseResource |
| 149 | + self.search = { |
| 150 | + display_count: false |
| 151 | + query: -> { |
| 152 | + # ... |
| 153 | + }, |
| 154 | + } |
| 155 | +end |
| 156 | +``` |
| 157 | + |
| 158 | +You can also assign a lambda to dynamically set the value. Inside that block you have access to all attributes of the [`Avo::ExecutionContext`](./../execution-context). |
| 159 | + |
| 160 | +```ruby{4} |
| 161 | +# app/avo/resources/user.rb |
| 162 | +class Avo::Resources::User < Avo::BaseResource |
| 163 | + self.search = { |
| 164 | + display_count: -> { user.admin? } |
| 165 | + } |
| 166 | +end |
| 167 | +``` |
| 168 | + |
| 169 | +</Option> |
| 170 | + |
| 171 | +## Scope out global or resource searches |
| 172 | + |
| 173 | +You may want to perform different searches on the `global` search from the `resource` search. You may use the `params[:global]` flag to figure that out. |
| 174 | + |
| 175 | +```ruby{5-11} |
| 176 | +# app/avo/resources/order.rb |
| 177 | +class Avo::Resources::Order < Avo::BaseResource |
| 178 | + self.search = { |
| 179 | + query: -> { |
| 180 | + if params[:global] |
| 181 | + # Perform global search |
| 182 | + query.ransack(id_eq: q, m: "or").result(distinct: false) |
| 183 | + else |
| 184 | + # Perform resource search |
| 185 | + query.ransack(id_eq: q, details_cont: q, m: "or").result(distinct: false) |
| 186 | + end |
| 187 | + } |
| 188 | + } |
| 189 | +end |
| 190 | +``` |
| 191 | + |
162 | 192 | ## Custom search provider
|
163 | 193 |
|
164 | 194 | You can use custom search providers like Elasticsearch.
|
|
0 commit comments