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

Add a last row to grid #41

Closed
fernandoalmeida opened this issue Feb 14, 2011 · 12 comments
Closed

Add a last row to grid #41

fernandoalmeida opened this issue Feb 14, 2011 · 12 comments

Comments

@fernandoalmeida
Copy link
Contributor

Hi!

How can i to add a last row to grid?

I need to show cumulative values to specifc columns, id this possible with wice grid?

Thanks.

@leikind
Copy link
Owner

leikind commented Feb 14, 2011

There is no API specially for the last row, but you can try to do this via the custom row feature: http://grid.leikind.org/adding_rows , http://leikind.org/apis/wice_grid/files/README_rdoc.html#addingrowstothegrid . The trick will be to know when the rendered row is the last one. You can use @your_grid_object.resultset.count to get the number of records page.

Is it Rails3?

@fernandoalmeida
Copy link
Contributor Author

Yes, Rails 3.

I tryed to develop the feature fallowing after_row and before_row examples:

#lib/grid_renderer.rb
attr_reader :last_row_handler
def last_row(&block)
@last_row_handler = block
end

#lib/wice_grid_view_helpers.rb
last_row_output = if rendering.last_row_handler
call_block_as_erb_or_ruby(rendering, rendering.last_row_handler, grid.resultset)
else
nil
end

  content << last_row_output if last_row_output

  content << '</tbody></table></div>'

This works to handle current page resultset but i want to handle all pages resultset, can i to do this?

I will pull request to you when all works.

Thank you very much.

@leikind
Copy link
Owner

leikind commented Feb 15, 2011

In my first reply to your problem I meant that you can implement your solution without changing the source code of the plugin. For accessing all records you can try this http://grid.leikind.org/integration_with_application , or, from inside the plugin you can try to use grid.resultset_without_paging_with_user_filters

@fernandoalmeida
Copy link
Contributor Author

Thanks leikind, worked now!

But i think also what the last_row method is more semantic and easier than to use conditional in all after_row. What do you think, do you want my patch?

Thank you one more time.

@leikind
Copy link
Owner

leikind commented Feb 15, 2011

Actually this seems like a possible feature. Let's just think what object will be injected into this block. In your code above I see that you are submitting the resultset. Do you think this is enough? I thought you want to perform calculations with all the records, and the resultset in the paginates mode represents only the current page (it's a will_paginate's paginate result object)

@fernandoalmeida
Copy link
Contributor Author

No, removed this parameter, i am passing nil instead.

call_block_as_erb_or_ruby(rendering, rendering.last_row_handler, nil)

@leikind
Copy link
Owner

leikind commented Feb 15, 2011

and what calculation do you do there in the last row? Do you access the grid object from there?

@fernandoalmeida
Copy link
Contributor Author

Yes, i used the :with_resultset callback to get all registers and show one line with page calcs and other with general calcs, in respective columns.

@grid_object.resultset.map(&:value).inject(:+)

@controller.all.map(&:value).inject(:+)

and others.

@leikind
Copy link
Owner

leikind commented Feb 15, 2011

Please submit the code if you like

@leikind
Copy link
Owner

leikind commented Feb 17, 2011

How does your grid declaration code with #last_column looks like by the way?

@fernandoalmeida
Copy link
Contributor Author

i made now the pull request with the code and usage example.

@leikind
Copy link
Owner

leikind commented Feb 18, 2011

Merged. See 3.0.0pre3

This issue was closed.
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