Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support filtering by specific columns #498

Open
1 task done
nacosdev opened this issue May 20, 2023 · 1 comment
Open
1 task done

Support filtering by specific columns #498

nacosdev opened this issue May 20, 2023 · 1 comment
Labels

Comments

@nacosdev
Copy link

nacosdev commented May 20, 2023

Checklist

  • There are no similar issues or pull requests for this yet.

Is your feature related to a problem? Please describe.

I want to be able to filter by specific column.

Describe the solution you would like.

Filtering by specific columns, having dropdowns for foreign keys or enums, yes or no options for booleans, and text inputs for varchars, etc., similar to Django Admin Filtering.

Describe alternatives you considered

This could be a path to start working with this:
Add filter filter_by as an array of string making refernce to the colums:

class UserAdmin(ModelView, model=User):
    filter_by = ["state_id"]

Declare the property in ModelView:

class ModelView(BaseView, metaclass=ModelViewMeta):
  ...
  filter_by: ClassVar[Optional[List[str]]] = []
  ...

Get filters from query params, in the list endpoint:

@login_required
async def list(self, request: Request) -> Response:
  """List route to display paginated Model instances."""
  ...
  filters = {}
  for col in model_view.filter_by:
    if col in request.query_params:
      filters[col] = request.query_params[col]
  # send filters to list method of the model_view instance
  pagination = await model_view.list(page, page_size, search, sort_by, sort, filters)

The next steps would be to actually filter for these fields in the list method of the ModelView and render the appropriate forms based on the active filters.

Additional context

No response

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@polar-sh polar-sh bot added the polar label Jun 28, 2023
@aminalaee aminalaee changed the title Soport filtering by specific columns Support filtering by specific columns Aug 31, 2023
@klonhero
Copy link

Related discussion, looks similar to this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants