dncuug / x.pagedlist Goto Github PK
View Code? Open in Web Editor NEWLibrary for easily paging through any IEnumerable/IQueryable in ASP.NET
Home Page: https://nuget.org/packages/X.PagedList
License: MIT License
Library for easily paging through any IEnumerable/IQueryable in ASP.NET
Home Page: https://nuget.org/packages/X.PagedList
License: MIT License
Good Day:
I have model when I convert it to pagedlistAsync it won't work and shows error on the page as this:
Could not load file or assembly 'Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
but when I do it like this :
var postsList = await model.ToListAsync();
var postsByPage = postsList.ToPagedList(pageNo ?? 1, 10);
ViewData["featuredHome"] = featuredPost as BlogListView;
if (Request.IsAjaxRequest())
{
return PartialView("_BlogPostsList", postsByPage);
}
return View(postsByPage);
it works only when I convert the model to listAsync then after I convert to PagedList.
I would like to know if that's issue or There is a mistake in my assemblies
Thanks
Does X.PagedList work on MVC6?
I have it working on an MVC5 project without any problems... But I recently started a new MVC6 project and I'm having trouble making PageList work. It fails to load the namespace, and the Helpers..
I haven't been able to make it work.
I experienced the same behavior installing the beta as was described here: #8
After the NuGet install the X.PagedList.Mvc .dll was no longer referenced in my project, the PagedList.Mvc namespace was compl As previously mentioned, the .dll did exist in a net45 directory and manually adding the reference addressed the issue. Perhaps the nuget bundling is the culprit?
I am strugling with the serialization of IPagedList using JSON.NET.
Also asked a question on StackOverflow(1) as it is maybe not an issue with this library per se, but that I have to implement a custom serializer/deserializer to make it work.
I have the following use case, I want to serialize/deserialize my IPagedList of T using JSON.net (Newtonsoft.Json). This seems not to be working. It does not serialize everything, only the items (or with my own ContractResolver, the object with empty properties).
A test case:
var list = new List(Enumerable.Range(1, 1000));
var paged = list.AsQueryable().ToPagedList(3, 10);
var json = JsonConvert.SerializeObject(paged); (output: [21,22,23,24,25,26,27,28,29,30])
var obj = JsonConvert.DeserializeObject<PagedList>(json);
Questions:
Found (2) which correctly makes me serialize the PagedList but that cannot convert back to the IPagedList, are there implementations for serialization for this library?
Hello, my first time ever posting in github!
Sorry in advance if I'm missing any guideline.
In the PagedListForEntityFramework when the pageNumber
is 1, no ordering is applied in the superset
before the .Take(pageSize)
:
Subset.AddRange(pageNumber == 1
? superset.Take(pageSize).ToList()
: superset.OrderBy(keySelector).Skip((pageNumber - 1) * pageSize).Take(pageSize).ToList());
I believe that the .OrderBy(keySelector)
should be applied on the superset
regardless if the pageNumber
is 1 or not:
Subset.AddRange(pageNumber == 1
? superset.OrderBy(keySelector).Take(pageSize).ToList()
: superset.OrderBy(keySelector).Skip((pageNumber - 1) * pageSize).Take(pageSize).ToList());
Thank you!
IEnumerable extensions no longer work using current version.
This extension method will call the superset enumerable multiple times which is not very effective.
But you can use the code from Split method which will fit perfectly (with one simple change)
public static IEnumerable<IEnumerable<T>> Partition<T>(this IEnumerable<T> superset, int pageSize)
{
return superset
.Select((item, index) => new { index, item })
.GroupBy(x => x.index / pageSize)
.Select(x => x.Select(y => y.item));
}
I have implemented Pagedlist.MVC and its working fine !
However, one issue I have which is as follows
In my application i have set the page size to 10 and I am retrieving the records same as page size(.i.e. 10 records) and not more than that.
However, while doing this Pagedlist package has disabled the next/prev button as my page size = number of records retrieved.
But, I have more records(say 150000) so in this case how can I keep the next/prev button enabled ??
I am not retrieving excess records due to performance issue. Hoever, I have the cound of total records.
So, how can I keep enable the next/prev button and also retrieve next 10 records ?
Regards,
Rohit
Can be added a UlElementattributes in PagedListRenderOptions to customize the attribute to add on ul tag.
public IDictionary<string, string> UlElementattributes { get; set; }
In HtmlHelper
if (options.UlElementattributes != null)
{
foreach (var c in options.UlElementattributes)
ul.MergeAttribute(c.Key, c.Value);
}
I'm trying to create a new paged list based on a paged list returned by Entity Framework. I'm converting the results to a view model object to flatten them. It is still a 1 to 1 relationship between my view model and entity result parent. So I was hoping I could just create a new paged list with the meta data from my entity query.
var newPagedList = new PagedList<viewModel>(dbResults.GetMetaData(), ViewModelList)
The problem is that GetMetaData() has a return type of IPagedList not PagedListMetaData
As a workaround I'm using:
var metadata = new X.PagedList.PagedListMetaData(dbResults);
var newPagedList = new PagedList<viewModel>(metadata, ViewModelList);
The work around works great and accomplishes what I want, but I was just thinking that IPagedList<>.GetMetaData() should return a type of PagedListMetaData
Is it possible to add a js function call to the link's onclick attribute instead of setting the href attribute? My grid has filters that use POST method and I have to keep them when navigating between pages.
Would love to see it revisited now that things are settling down! :)
The current X.PagedList.Mvc.Core library targets netstandard 1.6 which isn't supported in any current .NET Framework with the 1.0 tooling. This is a blocker for using this package with any ASP.NET Core applications targeting .NET Framework 4.x until the 2.0 tooling is realeased. It would be great if the target could be rolled back to the lowest possible netstandard to provide the widest range of compatibility.
I have a database of around 40000 objects.
If I try to show 100 items with page number 1 it works fine.
var users = context.Users.Include(c => c.Emails); users = users.OrderBy(c => c.Name); var selection = users.ToPagedList(1, 100); return View(selection);
But as soon as I try to show page number 2 I get a timeout exception on the following line:
var selection = carehomes.ToPagedList(2, 100);
Inner exception is as follows:
{System.Data.SqlClient.SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext
1 c)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func
3 operation, TInterceptionContext interceptionContext, Action3 executing, Action
3 executed)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
ClientConnectionId:0a24d923-552c-41d8-8520-72299810b494
Error Number:-2,State:0,Class:11}
Is there an option to not render the pagination control if there's no data?
At the moment what I get is "Page 1 of 0" which isn't great
PagedList currently passes 'int' to the .Skip() & .Take() methods of Entity Framework.
This means that the SQL generated does not parameterise these variables and prevents databases from caching the execution plan for the SQL.
Instead, if a lambda was passed to the .Skip() & .Take() methods, Entity Framework (EF6) would instead generate parameters for these variables and allow databases to better cache the execution plan.
See here for more information:
http://anthonychu.ca/post/entity-framework-parameterize-skip-take-queries-sql/
The current async implementation starts a task in a thread and does the work synchronously in this thread. We can often use an underlying async implementation instead of taking a thread (for instance with EF CountAsync / ToListAsync). Also the current implementation will do the Count inside the calling thread, I don't think this was expected.
An abstract AsyncPagedList with abstract methods for CountAsync and ToListAsync so we can add our own implementations without duplicating math on different properties may be usefull ... ?
Also, for your implementation, running the task on another thread, the whole process should be on the other thread and not only ToList : return Task.Factory.StartNew(() => new StaticPagedList<T>(superset.Skip<T>(((pageNumber - 1) * pageSize)).Take<T>(pageSize), pageNumber, pageSize, superset.Count<T>()));
Can be used a ActiveLiElementClass in PagedListRenderOptions to customize the active class.
I think it is the time to convert the pager HtmlHelper to TagHelper, clean up the code and remove the unnecessary if's.
I can't seem to have the ellipses on the pager enabled. However, I found some code here that seems to fix it. Are the ellipses supposed to work in the official X.PagedList on GitHub? Because then I have probably done something wrong in my code. Otherwise, it would be nice if we could get the fix into the official code.
Would be good to have InputFieldSize, InputFieldClass, etc.
I tried to replace X.PagedList from PagedList. But then there are many errors in the cshtml in my project although the project could be compiled and execute without any error. The error is as the following,
Error CS0012 The type 'IEnumerable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
How do we resolve it? I already target the project to .NET 4.6.1 and the version of X.PagedList is 5.3.0.5300
And my web.config already has added the following,
<system.web>
<compilation debug="true" targetFramework="4.6.1" >
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation>
Is it possible to add support to generating the pagination as
<input
type="submit" value="{pageNumber}"/>
from only generating
<a
href="generatedUrl" />?
I have too many parameters have to add to the Url.Action but all the values are already under the
tab.See this link for more information optimizing query for Skip
and Take
. This will enable for query cache.
Hello,
Is there a way to center page numbers between prev. button and next button.
Prev. button has float: left,
Next button has float: right;
Thanks.
there seems to be some binding mismatch on the nuget package for X.PagedList.Mvc6, please see error
'X.PagedList.Mvc6' with identity 'X.PagedList.Mvc6, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'X.PagedList, Version=5.0.5.1920, Culture=neutral, PublicKeyToken=abbb863e9397c5e1' which has a higher version than referenced assembly 'X.PagedList' with identity 'X.PagedList, Version=5.0.5.1782, Culture=neutral, PublicKeyToken=abbb863e9397c5e1'
When you install the nugget package for X.PagedList.Mvc, it also installs PagedList. The problem is that IPagedList exists in both dlls. And that makes visual studio halt error and not compile.
I'm using the newest version of X.PagedList.MVC, but I do not see a reference to the package in my project. I downgraded the package to 5.1.0.5000, and the package appears.
The async implementation is using Task.Factory.StartNew()
but that is not good in ASP.NET environment, it is better to be using the approach done by Entity Framework here because that is not creating a new thread.
You should write your tests with the given examples in the summary :o)
Splits a collection of objects into n pages with an (for example, if I have a list of 45 shoes and say 'shoes.Split(5)' I will now have 4 pages of 10 shoes and 1 page of 5 shoes.
[Fact]
public void Split_Works()
{
//arrange
var list = Enumerable.Range( 1, 45 );
//act
var splitList = list.Split( 5 );
//assert
Assert.Equal( 5, splitList.Count );
Assert.Equal( 10, splitList.ElementAt( 0 ).Count());
Assert.Equal( 10, splitList.ElementAt( 1 ).Count());
Assert.Equal( 10, splitList.ElementAt( 2 ).Count());
Assert.Equal( 10, splitList.ElementAt( 3 ).Count());
Assert.Equal( 5, splitList.ElementAt( 4 ).Count());
}
And now the test will fail, because each page contains 9 items.
Another failure or missing detail is, that the items are in a different order.
var splitList = Enumerable.Range( 1, 9999 ).Split( 10 );
will result into
{
{ 1, 11, 21, 31, 41, 51, ... },
{ 2, 12, 22, 32, 42, 52, ... },
...
{ 10, 20, 30, 40, 50, ... }
}
I do not think that this is expected
Please convert source files from CP1252 (or was it CP1251?) to UTF-8.
Specifically
https://github.com/kpi-ua/X.PagedList/blob/master/X.PagedList.Mvc/PagedListRenderOptions.cs#L28-L32
After updating X.Pagedlist from v5.3 to v7 with NuGet, the X.Pagedlist assemblies are not signed and my MVC app will not start.
Is there a reason for not signing the assemblies?
Hi,
I wonder how I can create the action link from current url and get the paging to work for it instead of building it from only a controller and action.
If this is the current url e.g: http://mydomain.com/urlparth1/urlpath2/
How can I just get the Html.PagedListPager to create paging urls like this
http://mydomain.com/urlparth1/urlpath2/?page=1
Is this possible?
Strange worked for me before I submitted PR to PagedList project, but now in this library when I do
someQuery.ToPagedList(int.MaxValue, 100);
then I get exception:
"Count must have a non-negative value.\r\nParameter name: count"
...Can anyone confirm whether this new feature works for them?
I m using the render
@Html.PagedListPager((IPagedList)ViewData.Model.EnumerableAds, page => Url.Action("MyPage", "Home", new { page }))
Which give me the HTML output:
<div class="pagination-container">
<ul class="pagination">
<li class="PagedList-skipToPrevious"><a href="/home/mypage?page=1" rel="prev">«</a></li>
<li><a href="/home/mypage?page=1">1</a></li>
<li class="active"><a>2</a></li>
<li><a href="/home/mypage?page=3">3</a></li>
<li class="PagedList-skipToNext"><a href="/home/mypage?page=3" rel="next">»</a></li>
</ul>
</div>
For the first item:
<li class="PagedList-skipToPrevious"><a href="/home/mypage?page=1" rel="prev">«</a></li>
<li><a href="/home/mypage?page=1">1</a></li>
i would like:
<li class="PagedList-skipToPrevious"><a href="/home/mypage" rel="prev">«</a></li>
<li><a href="/home/mypage">1</a></li>
I would like to remove ?page=1 for the first page.
Is it possible ?
Hello,
In PagedListPager we are calling method from URL.Action synchronously like follows,
@Html.PagedListPager((IPagedList)Model, page => Url.Action("Mailbox", new { page = page }), PagedListRenderOptions.Classic)
Can we call the same method through ajax ?
Regards,
Rohit
It works well locally, but breaks in production. If I copy System.Runtime.dll
from local bin to production bin, production also starts working. I tried to copy System.Runtime.dll
to custom folder and add reference to it, but got an error about duplicate references.
Ended up using original PagedList. Everything stared working after changing using declaration(to PagedList instead of X.PagedList) and no other changed had to be made.
I'm using it from razor view / MVC5 application.
Isn't it quite common to have the paging function in a distributed environment? Well, i can't deserialize either IPagedList or any concrete type deriving from IPagedList using JSON.NET. The error message is: Cannot create and populate list type X.PagedList.StaticPagedList`1
Hello,
On an ASP.NET MVC project and I have the following:
PagedList<TestModel> models = _service.Get(2, 20);
The service always return a PagedList but I need to create a List with only the items in PagedList and without the paging metadata.
I tried the following:
IList)models.GetEnumerator()
No success. Is it possible to convert a PagedList to List?
Thank You,
Miguel
after installing xpagedlist and memory dumping in production x.pagedlist is in debug mode
Hello,
How can I navigate(next-prev) between the records and NOT into the page ?
Regards,
Rohit
On initial load of a page the active page is 1. Then the page should not be clickable or be generated as an anchor. An empty is still clickable. The anchor should not be there.
<ul class="pagination">
<li class="active">
<a>1</a></li>
<li><a href="/Student/List?page=2">2</a>
</li>
</ul>
Got this error when tested my application for extreme values.
Solution: inside PagedList
constructor, this operation (pageNumber - 1) * pageSize
should be enclosed into checked
statement.
Another solution would be checking the same and throwing ArgumentOutOfRangeException("pageSize, pageNumber", "(pageSize - 1)*pageNumber cannot exceed int.MaxValue.")
I would like to use this page controller with other filter engine
Is it possible to combine it all together and pass filter settings with pagenumber simultaneously
like
@Html.PagedListPager(Model.Data, page => Url.Action("Index", new { model = model, pageNumber = page }))
my project is based on mvc.core
Hi, I try to used X.PagedList on VB MVC 5 project but does not successful.
The error shown are.
Error BC30519 Overload resolution failed because no accessible 'PagedListPager' can be called without a narrowing conversion:
Extension method 'Public Function PagedListPager(list As IPagedList, generatePageUrl As Func(Of Integer, String)) As MvcHtmlString' defined in 'HtmlHelper': Argument matching parameter 'list' narrows from 'IEnumerable(Of IdentityRole)' to 'IPagedList'.
Extension method 'Public Function PagedListPager(list As IPagedList, generatePageUrl As Func(Of Integer, String)) As MvcHtmlString' defined in 'HtmlHelper': Argument matching parameter 'list' narrows from 'IEnumerable(Of IdentityRole)' to 'IPagedList'.
can anyone give me idea/sample on how to properly do it. already try to search on google but did not find helpful answer.
Thanks in advance..
Would love to see this implemented as an alternative paging strategy!
A little thinking on the matter:
https://www.sitepoint.com/paginating-real-time-data-cursor-based-pagination/
You can also look into how Facebook and Twitter approach the topic.
Is there documentation for this package's features that are not in the base package?
If I knew what they are, I could help write the docs.
I have my table connected to a SQL View. table (which constructs columns from many different tables.)
When I feed this data into X.PagedList or the older PagedList; everything is working fine until I click a page higher then 9! (Code is Erroring out with SQL Server not responding or time out) I don't know why this is happening only with my "View" data not any "table" data.
When I move between pages, the entire page is posting back instead of just the element that I have I identified in UpdateTargetID.
Is this a bug or something wrong with my code.
Here is my View code. You can see I would like to update the div with an ID of "News" as I move through pages.
@using PagedList.Mvc;
@using PagedList;
@model Framework.Models.FrameworkModel
<h1 class="hidden">@Html.Raw(Model.Page.Heading)</h1>
<div class="main-container-home">
@Html.Raw(Model.Page.Body)
<div class="news" id="News">
@foreach (var article in ViewBag.PageOfData)
{
<article itemscope itemtype="http://schema.org/NewsArticle">
<h2 class="block" itemprop="headline">@Html.Raw(article.Title)</h2>
<img alt="@Html.Raw(article.Title)" class="news-image-@(article.ImageAlignment)" height="@(article.ImageHeight)" src="@(article.Image)" style="border-width: 0;" title="@Html.Raw(article.Title)" width="@(article.ImageWidth)" itemprop="image" />
<div class="news-container">
@Html.Raw(article.Summary)
@if(!string.IsNullOrEmpty(article.Url))
{
<div class="news-link">
<a href="@(article.Url)" target="@(article.UrlTarget)" title="@Html.Raw(article.UrlText)" itemprop="url">@Html.Raw(article.UrlText)</a><br />
</div>
}
</div>
</article>
}
</div>
@if (ViewBag.PageCount > 1)
{
<div class="news-pager">
@Html.PagedListPager((IPagedList)ViewBag.PageOfData, page => Url.Action("News", new {page=page}), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(PagedListRenderOptions.PageNumbersOnly, new AjaxOptions() { HttpMethod = "GET", UpdateTargetId = "News" }))
</div>
}
</div>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.