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

Update Query dynamicly #652

Closed
DominikLazarAPAG opened this issue Jun 14, 2024 · 4 comments
Closed

Update Query dynamicly #652

DominikLazarAPAG opened this issue Jun 14, 2024 · 4 comments

Comments

@DominikLazarAPAG
Copy link

Is your feature request related to a problem? Please describe.
I want to make a table dynamically filterable within a single LiveView. Currently, I need to use a separate LiveView to configure the fields and then navigate to the LiveView with the table that uses the built query. This setup is clumsy, and I would like to change the query within the same LiveView.

Describe the solution you'd like
I would like the ability to update the query externally at runtime. The component should fetch and display new data based on the updated query parameters using a refresh mechanism.

Describe alternatives you've considered
-Building the query from parameters beforehand, which does not offer true dynamic filtering.
-Defining multiple tables with possible filters and rendering only the needed one. This approach is inefficient and currently not working as expected because only one table is rendered and switching between different tables is not possible. This might be a bug.

By enabling dynamic query updates, users will have a more flexible and efficient way to interact with the data tables.

@alanvardy
Copy link
Owner

Hello and thank you for the feature request.

Thinking about how this could be implemented. I could let you pass in a module and function, and every time the query is built it can pass the query and the state to that module/function dynamically. You would be able to modify the query and then it is sent back.

So you could use a GenServer / ETS / whatever to hold state and modify that query however you wish.

 use Exzeitable,
    repo: YourApp.Repo,
    routes: Routes,
   ...
   modify_query: {MyApp.MyModule, :my_function}

And then you can define that function elsewhere

defmodule MyApp.MyModule do
  def my_function(query, _state) do
     # Make your modifications and return the new query
    query
  end
end

Does this sound like it would meet your usecase?

@DominikLazarAPAG
Copy link
Author

Yes this sounds very useful, thank you

@alanvardy
Copy link
Owner

Adding feature in this PR: #654

@alanvardy
Copy link
Owner

This is now released as part of 0.6.5, thanks again!

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

No branches or pull requests

2 participants