Question.How do yo fetch paged data from database #2732
-
Have been looking through samples. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
@Johnka2 there used to be a couple different paging samples, but they've faded away I see. One was pretty cool, for smart clients, as it would do background loading of pages of data while the user was on a page/form. The other was probably what you are looking for - a server-side web paging model. Fortunately, the answer is pretty straightforward, though there are various ways to do the implementation. Basically, you want a ReadOnlyListBase subclass that represents the current page of data shown to the user. That part is pretty obvious. The question is how to retrieve pages of data. public class MyPage : ReadOnlyListBase<MyPage, MyItem>
{
[Fetch]
private void FetchPage(int pageNumber, [Inject] IMyItemDal dal)
{
var data = dal.GetPageOfData(pageNumber);
// load this object with `data`
}
} You may also want to get the total number of items up front, which can be done, along with getting the first page of data, via a command object: public class MyItemListLoader : ReadOnlyBase<MyItemListLoader>
{
// declare properties for FirstPage (type of MyPage) and PageCount (type of int)
[Fetch]
private void Fetch([Inject] IMyItemDal dal, [Inject] IChildDataPortal<MyPage> dp)
{
PageCount = dal.GetPageCount;
FirstPage = dp.Fetch(1); // fetch page 1
}
} |
Beta Was this translation helpful? Give feedback.
-
Your right about what am looking for. |
Beta Was this translation helpful? Give feedback.
-
I get the idea. |
Beta Was this translation helpful? Give feedback.
-
Thanks |
Beta Was this translation helpful? Give feedback.
@Johnka2 there used to be a couple different paging samples, but they've faded away I see.
One was pretty cool, for smart clients, as it would do background loading of pages of data while the user was on a page/form.
The other was probably what you are looking for - a server-side web paging model. Fortunately, the answer is pretty straightforward, though there are various ways to do the implementation.
Basically, you want a ReadOnlyListBase subclass that represents the current page of data shown to the user. That part is pretty obvious. The question is how to retrieve pages of data.