patricklindsay / wice_grid

A Rails grid plugin to create grids with sorting, pagination, and (automatically generated) filters
http://wicegrid.herokuapp.com/
MIT License
33 stars 29 forks source link

Wrong number of rows on per_page method #67

Open arielwulkan opened 5 years ago

arielwulkan commented 5 years ago

I'm getting a mismatch between the per_page and number of row actually rendered although the results count is correct.

the code:

Controller:

def providers
    @employee_certifications_grid = initialize_grid(EmployeeCertification.includes(employee: [:orders]).where(status: "active",employees: {status: "active"},orders: {taker_id: current_company.id}), order_direction: 'asc', per_page: 15)
  end

View:

<section class="section">
  <div class="columns is-centered">
    <div class="column">
      <%= grid(@employee_certifications_grid) do |g|

        g.column name: 'Colaborador', attribute: 'nome', assoc: :employee, filter: false

        g.column name: 'Documento', attribute: 'name', assoc: :certification, filter: false

        g.column name: 'Descição', attribute: 'title', assoc: :certification, filter: false

        g.column name: 'Arquivo', filter: false do |employee_certification|
          link_to employee_certification.document.filename, employee_certification.document, target: :_blank 
        end

        g.column name: 'Validade', attribute: 'expiration_date', filter: false do |employee_certification|
          if employee_certification.expiration_date
            if employee_certification.expiration_date < employee_certification.employee.orders.active.minimum(:due)
              [employee_certification.expiration_date.strftime("%d/%m/%Y"), {style: 'background-color: rgb(255, 105, 104);'}]
            else
              employee_certification.expiration_date.strftime("%d/%m/%Y")
            end
          else
            "--"
          end
        end

        g.column name: 'Pedidos', filter: false do |employee_certification|
          link_to 'visualizar pedidos', root_path
        end

      end -%>

      <p>
        IDs of records on the current page:
        <%= @employee_certifications_grid.current_page_records.map(&:id).to_sentence %>
      </p>
      <p>
        IDs of all records:
        <%= @employee_certifications_grid.all_pages_records.map(&:id).to_sentence %>
      </p>
    </div>
  </div>
</section>

Image of the result: 2019-03-01 1

JasonBarnabe commented 5 years ago

Same as #60?

arielwulkan commented 5 years ago

Looks similar. I'm in Rails 5.2.0, though. So it should be corrected.

https://github.com/patricklindsay/wice_grid/issues/60#issuecomment-464150282

arielwulkan commented 5 years ago

The problem persists even when not using the per_page method As in:

def providers
    @employee_certifications_grid = initialize_grid(EmployeeCertification, include:[:certification,{employee: :orders}] , conditions: {status: "active", employees: {status: "active"}, orders: {taker_id: current_company.id}} )
  end

2019-03-01 3

Vinnie1991 commented 5 years ago

Is there an update for this?

afdev82 commented 4 years ago

Maybe this commit could fix this problem: https://github.com/kreintjes/wice_grid/commit/e3006b3c65a482543bf2d8401025fe28662dc312