feat: add "searchable" column support for grids
frontend / basic only
This commit is contained in:
		
							parent
							
								
									770c4612d5
								
							
						
					
					
						commit
						a042d511fb
					
				
					 4 changed files with 65 additions and 0 deletions
				
			
		|  | @ -282,6 +282,12 @@ class Grid: | |||
| 
 | ||||
|        Only relevant if :attr:`paginated` is true.  If not specified, | ||||
|        constructor will assume ``1`` (first page). | ||||
| 
 | ||||
|     .. attribute:: searchable_columns | ||||
| 
 | ||||
|        Set of columns declared as searchable for the Vue component. | ||||
| 
 | ||||
|        See also :meth:`set_searchable()` and :meth:`is_searchable()`. | ||||
|     """ | ||||
| 
 | ||||
|     def __init__( | ||||
|  | @ -306,6 +312,7 @@ class Grid: | |||
|             pagesize_options=None, | ||||
|             pagesize=None, | ||||
|             page=1, | ||||
|             searchable_columns=None, | ||||
|     ): | ||||
|         self.request = request | ||||
|         self.vue_tagname = vue_tagname | ||||
|  | @ -344,6 +351,9 @@ class Grid: | |||
|         self.pagesize = pagesize or self.get_pagesize() | ||||
|         self.page = page | ||||
| 
 | ||||
|         # searching | ||||
|         self.searchable_columns = set(searchable_columns or []) | ||||
| 
 | ||||
|     def get_columns(self): | ||||
|         """ | ||||
|         Returns the official list of column names for the grid, or | ||||
|  | @ -543,6 +553,28 @@ class Grid: | |||
|                 return True | ||||
|         return False | ||||
| 
 | ||||
|     def set_searchable(self, key, searchable=True): | ||||
|         """ | ||||
|         (Un)set the given column's searchable flag for the Vue | ||||
|         component. | ||||
| 
 | ||||
|         See also :meth:`is_searchable()`.  Flags are tracked via | ||||
|         :attr:`searchable_columns`. | ||||
|         """ | ||||
|         if searchable: | ||||
|             self.searchable_columns.add(key) | ||||
|         elif key in self.searchable_columns: | ||||
|             self.searchable_columns.remove(key) | ||||
| 
 | ||||
|     def is_searchable(self, key): | ||||
|         """ | ||||
|         Check if the given column is marked as searchable for the Vue | ||||
|         component. | ||||
| 
 | ||||
|         See also :meth:`set_searchable()`. | ||||
|         """ | ||||
|         return key in self.searchable_columns | ||||
| 
 | ||||
|     def add_action(self, key, **kwargs): | ||||
|         """ | ||||
|         Convenience to add a new :class:`GridAction` instance to the | ||||
|  | @ -1384,8 +1416,13 @@ class Grid: | |||
|                'field': 'foo', | ||||
|                'label': "Foo", | ||||
|                'sortable': True, | ||||
|                'searchable': False, | ||||
|            } | ||||
| 
 | ||||
|         The full format is determined by Buefy; see the Column section | ||||
|         in its `Table docs | ||||
|         <https://buefy.org/documentation/table/#api-view>`_. | ||||
| 
 | ||||
|         See also :meth:`get_vue_data()`. | ||||
|         """ | ||||
|         if not self.columns: | ||||
|  | @ -1397,6 +1434,7 @@ class Grid: | |||
|                 'field': name, | ||||
|                 'label': self.get_label(name), | ||||
|                 'sortable': self.is_sortable(name), | ||||
|                 'searchable': self.is_searchable(name), | ||||
|             }) | ||||
|         return columns | ||||
| 
 | ||||
|  |  | |||
|  | @ -53,6 +53,7 @@ | |||
|                            label="${column['label']}" | ||||
|                            v-slot="props" | ||||
|                           :sortable="${json.dumps(column.get('sortable', False))|n}" | ||||
|                           :searchable="${json.dumps(column.get('searchable', False))|n}" | ||||
|                            cell-class="c_${column['field']}"> | ||||
|           % if grid.is_linked(column['field']): | ||||
|               <a :href="props.row._action_url_view" | ||||
|  |  | |||
|  | @ -95,6 +95,12 @@ class AppInfoView(MasterView): | |||
| 
 | ||||
|         g.sort_multiple = False | ||||
| 
 | ||||
|         # name | ||||
|         g.set_searchable('name') | ||||
| 
 | ||||
|         # editable_project_location | ||||
|         g.set_searchable('editable_project_location') | ||||
| 
 | ||||
|     def get_weblibs(self): | ||||
|         """ """ | ||||
|         return OrderedDict([ | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lance Edgar
						Lance Edgar