I am trying to implement a filter action on a list of tasks where I create a button or link that can filter the tasks with respect to their completion status the task list has a description: string and a completion: boolean I have implemented a search function on description before and know that I need to create a search function after taking input about what to search from templates/task/index.html.heex in the form of search_input
<%= form_for @conn, task_path(@conn, :index), [class: "pull-right"], fn f -> %>
<%= search_input f, :query %>
<%= submit "Search" %>
<% end %>
and then implement some changes like-
# changing _params->params so that the search query is not neglected
# task-controller.ex
def index(conn, params) do
tasks = Tasks.list_tasks(params)
render(conn, "index.html", tasks: tasks)
end
also the list_tasks function is defined here-
def list_tasks(params) do
search_term = get_in(params, ["query"])
Task
|> Task.search(search_term)
|> Repo.all()
end
the search function is an ecto query which goes like this-
def search(query, search_term) do
from task in query,
where: ilike(task.title, search_term)
end
but I do not know of how to create a button to filter completion status which is a Boolean, I thought of creating a function which return string “true” if the input is :true but that doesn’t seem a good to way to do this, so please help me out, any link related to implementing search, filter and pagination function without any library will be helpful and appreciated