leikind / wice_grid

A Rails grid plugin to create grids with sorting, pagination, and (automatically generated) filters
MIT License
537 stars 213 forks source link

Limit records in the grid #143

Closed amey1908 closed 10 years ago

amey1908 commented 10 years ago

I am not sure if there is a problem with my query or something else. I need to limit the number of records to 10 in the query shown below. However, wice grid comes up with all records. Any idea what's the issue?

The initialize_grid code: @questions = initialize_grid(Question.limit(10))

leikind commented 10 years ago
@questions = initialize_grid(Question, per_page: 10)
amey1908 commented 10 years ago

Thanks Yuri for your prompt reply. I am not trying to limit the number of records per page, but I want to show only a total of 10 records. I have three tiers of subscription for my website. And the free user gets to see only 10 questions, while for paying customers, it would show all questions.

leikind commented 10 years ago

I see. Well, both .limit(10) and per_page: 10 translate to the same SQL, so I think that the plugin overwrites your limit with its implicit page limit. Could you maybe try

@questions = initialize_grid(Question.limit(10), per_page: 10)

?

amey1908 commented 10 years ago

Yuri, unfortunately it still shows all questions with 10 questions each page.

leikind commented 10 years ago

unfortunately it seems like it is not possible right now

amey1908 commented 10 years ago

Thanks Yuri for your prompt responses. One last thing - is there a way to restrict the number of records shown at the grid level (code where I write what columns to show in the grid) rather than the query level (code where I initialize the grid).

leikind commented 10 years ago

I don't understand the question. Why don't you use conditions in initialize_grid?