I need to implement some logic for to show 3 elements on the first page and by 1 element on all the next. For the first page there is no problems:
items = #model.limit(#first_page_items)
and for all the next ones i tried:
#model.offset(#first_page_items).page(#current_page - 1).per(#per) #makes no offset at all - all the items going from the beginning
#model.page(#current_page - 1).per(#per).offset(#first_page_items) #produces 4-th element on the second page and stays on it for ever
What am I doing wrong? thx
Related
I want to count below element, but actually it counts only the elements that are in the display on screen. So if i have 100 elements I need to scroll down more. How can I include the others in the count too?
It depends on how is your application implemented.
Now, developers usually reuse the resource to display those stuff to avoid wasting resources.
For example, you have below table
[index][content]
1-A
2-B
3-C
4-D
5-E
When you scroll down, the first element will be disappeared, and developer use that resource to display right behind the last element (or they will use a-buffer-element to display - e.g: index=6)
[index][content] - after you scrolled down
2-B
3-C
4-D
5-E
6-F (first resource here - or it is the buffer resource)
With that implemented way, you can't use "xpath_count" to count.
Let's try to scroll down (use for loop to count the number of elements in a page - then scroll down and continue counting them)
I'm implementing infinite scroll with will_paginate and ajax. Whenever I press the 'load more' elements, it brings me the next 4 elements in the collection. At the moment, everything is ok. But when I remove some element of some page, the next page has been already established in the 'load more' button; because of this, the next time I press the 'load more' button, one element is skipped. Does anybody know how can I solve this? (Sorry about my english)
Pagination gems don't work very well in your use case.
The easiest way to solve this is: if you have a list of elements ordered by e.g. id, on your next page request send the id of the last element on the current page, and use it to offset the next page.
What is happening is that pagination isn't eager loading the next set, but instead is doing an offset count
initial index + page_length * (page number - 1)
limit page_length
When you delete an element it forward shifts the index of every element after it in the database for this query. Which leaves your front end element indexes at a different state than the backend has.
You will need to re-load every "page" starting with the one containing the deleted element and work to the latest loaded "page" to get the front end to have the same element indexes that the back end has.
Assuming that I have a Title, sub detail and footer. Both footer and title are static (won't change) while the sub detail is dynamic, basically drawing a table from a database.
How is it possible to make it load a specific amount of lines in the Sub-detail and creating as much pages as needed? Let's say I have 30 lines in my database table. and I want to limit 10 lines per page. that will make it 3 pages
you could have a local variable keeping track of the number of time the detail before print event has been called. Once it hits 10 call NewPage()
You can use a child band
Enter your text in the child band, and when the data is more than one page, place a portion of your data on the next pages.
You can have more than one child band.
I'm showing a total of records in the footer of the page but is showing it for each page is any option for show it just in the last one?
That is the correct way i.e use ReportFooter instead of PageFooter. If you wish to print the total at the bottom of the last page, you can set ReportFooter's PrintAtBottom property to true.
the SearchFieldDemo works well for me, but has one problem: when you add a new country to the KeywordFilterList through the menu and that new item is on the bottom of the sorted list, then the user doesn't see anything and is unsure if the new item has been added or not.
A solution would be to make the KeywordFilterList scroll to the new item, but I can't figure out, how to do that. I've tried:
void addElementToList(Country country)
{
_countryList.addElement(country);
_keywordFilterField.updateList();
int index = _countryList.getIndex(country);
System.err.println("XXX index: " + index);
_keywordFilterField.setSelectedIndex(index);
}
But this does not have any effect: the printed index is correct and the KeywordFilterList scrolls, but not to a correct spot.
Any ideas please?
Alex
In the sample app you might have noticed the _keywordFilterField.setKeyword(""); line as the first thing they do before adding a new item to the list. This is to guarantee the new item will be visible in the list. Otherwise with some filter applied the list may not display the new item.
So in your code it looks like you don't handle this point. As a result the index you get with int index = _countryList.getIndex(country); may not be the same as it is in the visible filtered by some current keyword list. BTW, to find the index in the visible list you could use the ReadableList which can be got with _keywordFilterField.getResultList().
So the workflow could be as follows:
reset keyword by _keywordFilterField.setKeyword(""); - now there is no filtering applied so the visible list should include a new item.
add a new item to the underlying collection - _countryList.addElement(country);
call _keywordFilterField.updateList(); to refresh the ListField.
to be on the safe side find an index to scroll to by using the collection got by calling the _keywordFilterField.getResultList()
select the new item with _keywordFilterField.setSelectedIndex(index);