Giter Site home page Giter Site logo

Comments (6)

joeaudette avatar joeaudette commented on August 15, 2024 1

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.

yaseralnajjar avatar yaseralnajjar commented on August 15, 2024

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.

joeaudette avatar joeaudette commented on August 15, 2024

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.

yaseralnajjar avatar yaseralnajjar commented on August 15, 2024

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.

joeaudette avatar joeaudette commented on August 15, 2024

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.

yaseralnajjar avatar yaseralnajjar commented on August 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.