Thursday, April 20, 2017

Re: Dynamic Selector with Django/Jquery

On Saturday 15 April 2017 17:31:50 Anonymous Coder wrote:

 

> I need to filter lists of items to be displayed upon user selection in

> my list view.

> For instance if user selects 12 it should show only 12 products per

> page and so on.

 

For this specific issue:

https://docs.djangoproject.com/en/1.11/topics/pagination/

 

And quite easy to do with django.views.generic.ListView.

 

> My Django view has vairble items like below:

>

> items=Items.objects.all()

> Now I need to get products as per user selection how would i do that?

>

> <form>

> <span>Show:</span>

> <select class="orderby number" name="page_size">

 

Add onchange="this.form.submit()".

And tie page_size to the Paginator (paginate_by attribute on ListView) through urls.py.

 

If you need more dynamic filtering (sort order / color filter etc), you

may want to look at one of these:

 

https://djangopackages.org/grids/g/filters/

--

Melvyn Sopacua

No comments:

Post a Comment