Comments (6)
The way I would do it is make your method GetAgentStudents return Paged Result of T of your model. ie pass in pagenumber and pagesize as params and only retrieve one page of data at a time from the db.
from cloudscribe.web.pagination.
I made a decorator fix:
public class PagedListViewModel<T> : PagedList<T> where T : class
{
public PagedListViewModel(IEnumerable<T> source, int index, int pageSize, int? totalCount = null) :
this(source.AsQueryable(), index, pageSize, totalCount)
{
}
public PagedListViewModel(IQueryable<T> source, int index, int pageSize, int? totalCount = null) :
base(new List<T>(), index, pageSize, totalCount ?? source.Count())
{
var offset = (pageSize * index) - pageSize;
base.AddRange(source.Skip(offset).Take(pageSize));
}
}
from cloudscribe.web.pagination.
If you set the pagesize as 10 and only have 7 items then of course it will not show the pager, that is how it is supposed to work. You are passing in 10 as the page size:
var model = allProducts.ToPagedList(currentPageNum, 10);
You have not reported any real bug that I can see.
Sorry but I have no plans for any new 1.x releases of any of my projects. I cannot understand why anyone would still be using asp.net core 1.x, I don't think very many people are still using it. I recommend update your own projects to 2.x.
Myself I do not even use PagedList of T class at all. If I were starting this project today I would not even include that. I return PagedResult of T from my page queries.
I regret ever including the PageList of T class in this project and don't care to support it myself. It is a small class so you are free to copy it and "fix" it as you see fit. It is not used in the demo project and I don't ever use it in my own projects. There are also other PagedList of T implementations out there, so you may be able to find a better one. This project is mainly about the PaginationTagHelper which does not rely on PageList of T.
from cloudscribe.web.pagination.
Yes the pager won't show but also there won't be any items on the view!
The actual bug is in PagedList of T class... it will be simply empty if you did as above while it should contain the 7 elements, right?
*The PagedResult class only exists in the newer version of the package, and migrating into asp core 2.x would take lots of time to know about all the caveats.
Anyways, I've already managed by adding that decorator... a tip for other people to not use that class would help 😄
from cloudscribe.web.pagination.
perhaps, I would have to see more of your code to know if it is a bug, but if it is a bug it is not one that I plan to fix as I plan to remove that class from this project in a future release. As I said you can use your own copy of that class or find a better one.
In general I think one should return a page of data from the db not return all data and then make a PagedList from it.
I don't want to encourage people to use that class at all. It was originally included from another project and was only included for use in the demo app, but later I removed it from the demo app because I don't want people to use it and having it in the demo encouraged people to use it. At that time I left it in for backward compat in case anyone was using it, but now as bug reports come in for it I just want to remove it completely.
I recommend if you want to use PageList of T, then copy it into your own project and maintain it there because I plan to remove it from this project in a future release.
from cloudscribe.web.pagination.
I reproduced it in the attachment.
Pagination.zip
My actual code is projecting data then making a PagedList:
public async Task<IActionResult> Index(string searchTerm = null, int page = 1)
{
ViewBag.SearchTerm = searchTerm;
var agent = await _userManager.GetUserAsync(User);
var identity = (ClaimsIdentity)User.Identity;
var claimsPrincipal = new ClaimsPrincipal(identity);
var students = _agentStudentService.GetAgentStudents(agent, claimsPrincipal)
.FilterByNameOrEmail(searchTerm)
.ToStudentDetailsViewModels(_environment);
var result = students.ToPagedListViewModel(page, 5);
return View(result);
}
Where students is an IQueryable of StudentDetailsViewModel.
Do you suggest any other better approach?
from cloudscribe.web.pagination.
Related Issues (20)
- Changing css of cs-pager HOT 1
- totalitems with long type HOT 4
- Reference to cloudscribe.Pagination.Models HOT 5
- ToPagedList performance on IQueryable implementation HOT 1
- EINVRES Request to https://bower.herokuapp.com/packages/jquery failed with 502 (fix included) HOT 1
- CompatibilityVersion.Version_2_2 causing NRE HOT 1
- Remove Next and Previous Links HOT 2
- hashtag HOT 4
- reconsider support preserve querystring for creating link HOT 3
- `PagedResult<T> where T : class` why class is needed? HOT 3
- Calling Javascript functions HOT 6
- Add .NET Core 3.0 support HOT 9
- Add netstandard 2.1 Support HOT 1
- Can't use page for cs-pagenumber-param HOT 3
- Problem with total Items
- Please upgrade to .net 6 HOT 4
- How to target another page in Pager Links
- Plans to support .NET 7? HOT 1
- Bootstrap 5 support? HOT 4
- Test and fix demo Pagination web application HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cloudscribe.web.pagination.