Skip to content

Sorting and filtering made easy for your ASP.NET Core project. Shortcuts. custom model binders and other goodies for Panner. Easy-peasy.

License

Notifications You must be signed in to change notification settings

OSDKDev/Panner.AspNetCore

Repository files navigation

Panner.AspNetCore Nuget Coverage Status

Sorting and filtering made easy for your ASP.NET Core project! From CSV input to a filtered/sorted IQueryable with no effort using Panner, with extra shortcuts, custom model binders, and other goodies.

For more options, see Panner's documentation.

Usage

// Your action method!
[HttpGet]
// Sample request: /entities?sorts=CreatedTimeStamp,Id&filters=Name=Foo||Name=Bar,IsVisible=True
public async Task<IActionResult> GetAllPosts(
	[FromServices] DbContext myDbContext,

	// Add the following parameters to parse/validate csv inputs into particles.
	// Custom model binders take care of converting the csv string into a collection of particles.
	[FromQuery] IReadOnlyCollection<ISortParticle<MyEntity>> sorts,
	[FromQuery] IReadOnlyCollection<IFilterParticle<MyEntity>> filters
)
{
	var result = await myDbContext.MyEntity
			.Apply(filters)	// Apply validated and parsed filters
			.Apply(sorts)	// Apply validated and parsed sorts
			.ToArrayAsync();

	return Ok(result);
}

Setup

// Startup.cs
public void ConfigureServices(IServiceCollection services)
{

	services.AddMvc(); // Or maybe you're using .AddControllers()!

	services.UsePanner(c =>
	{
		// Entity wide configuration (Option 1)
		c.Entity<Post>()
		    .AllPropertiesAreSortableByName();
		    .AllPropertiesAreFilterableByName();

		// A more granular approach (Option 2)
		c.Entity<MyEntity>()
			.Property(x => x.Id, o => o
				.IsSortableAs(nameof(Views.Post.Id))
				.IsFilterableAs(nameof(Views.Post.Id))
			)
			.Property(x => x.Title, o => o
				.IsSortableAs(nameof(Views.Post.Title))
			)
			.Property(x => x.CreatedOn, o => o
				.IsSortableAs(nameof(Views.Post.Creation))
				.IsFilterableAs(nameof(Views.Post.Creation))
			);
	});
}

About

Sorting and filtering made easy for your ASP.NET Core project. Shortcuts. custom model binders and other goodies for Panner. Easy-peasy.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages