Creating Query Filters in the Database and Display in html

I just created a template with lots of filter options.

Date Home(type: date)
End Date(type: date)
Status by “select fixed”(type: select)
Source(type: text)

In this date field I want to put a “between”,

column of the bank that exists, the date is called
field :calldate, :naive_datetime

Now I need to make this template do a select directly in the database as the fields are filled.

And be shown only what was passed.
I do not intend to use rummage_phoenix

Can you help me?

Below is my files



    <div class="input-group-prepend">
      <div class="input-group-text"><i class="fas fa-calendar-alt"></i></div>
    <input type="date" class="form-control" id="inlineFormInputGroupDatestart" placeholder="Data">


 <select class="custom-select my-1 mr-sm-2" id="inlineFormCustomSelectPref">
   <option selected></option>
   <option value="">Todas</option>
   <option value="Atendida">Atendida</option>


    <div class="input-group-prepend">
       <div class="input-group-text"><i class="fas fa-map-marker"></i></div>
    <input type="text" class="form-control" id="inlineFormInputGroupSource" placeholder="Origem">

Page Controller:

  import Ecto.Query

  def index(conn, params) do
    cdr = Structure.list_cdr()

   page = Structure.list_cdr
	|> order_by([c], desc: c.calldate)
        |> Repo.paginate(params)

    render(conn, "index.html", cdr: cdr, cdr: page.entries, page: page)

What ‘specifically’ are you needing help with?

I needed to make a screen where the user searches the database directly

I solved it as follows …


  def index(conn, params) do

    page = Structure.list_cdr
      |> order_by([c], desc: c.calldate)
      |> Repo.paginate(params)
    filter = Structure.list_filter(params)
    date_start = get_in(params, ["date_start"])
    date_end = get_in(params, ["date_end"])
    status = get_in(params, ["status"])
    origem = get_in(params, ["origem"])
    destino = get_in(params, ["destino"])
    contexto = get_in(params, ["contexto"])
   render(conn, "index.html", cdr: page.entries, page: page, cdr: filter.entries, 
   filter: filter, date_start: date_start, date_end: date_end, status: status, origem: origem,
   destino: destino, contexto: contexto)


 def list_filter(params) do
     |> where_calldate(params)
     |> where_status(params)
     |> where_origem(params)
     |> order_by([c], desc: c.calldate)
     |> Repo.paginate(params)

Thank you for your interest in helping me.

1 Like