I would like to create a custom list view (in the backoffice), much like what comes as standard in Umbraco (Doc Type List View Option).
Except I would like to filter the results based on a category dropdown.
I have a Dropdown datatype with some values in it and I would like to filter the table of results based on the category selected.
Can anyone point me towards an example? I know how to create a custom view as an App_Plugin) and I've got my dropdown populated - I just don't know how to adjust the result set based on what I select.
OK, it's not mine either, but I can see that in the example the controller has a value called $scope.items that contains a list of all the items in the listview.
So you could perform a filter on this within the activate function, something like:
That would just return all the items who have a contentTypeAlias that equals "whatEver". You'd just need to make the comparison value the selected value of your list and then compare it to one of the properties that item has. If it's a custom property then each item has an array of properties for these.
If you add:
console.log($scope.items)
to your controller then you can use chrome dev tools console to see all the values. Hope that gives you some help?
Sorry, Paul, from reading that thread there doesn't seem to be any simple way to do that. Does your filter have to use a Dropdown Datatype - could you not just hardcode a select list?
I've managed to get it working, however the filtered results seems to reset themselves when you use the pagination - any thoughts on how I can get around this?
That's a shame as I've just ran in to the exact same issue.
I've got the listview only showing the items I want to display but they are spread across multiple pages. If the item doesn't appear on page 2 for example, I get a blank page.
Customized List views and Filters
Hello,
I would like to create a custom list view (in the backoffice), much like what comes as standard in Umbraco (Doc Type List View Option).
Except I would like to filter the results based on a category dropdown.
I have a Dropdown datatype with some values in it and I would like to filter the table of results based on the category selected.
Can anyone point me towards an example? I know how to create a custom view as an App_Plugin) and I've got my dropdown populated - I just don't know how to adjust the result set based on what I select.
Thanks
Paul
Does anyone know how I can do this?
So you are using a custom listview layout? I'm presuming you have seen this article - https://24days.in/umbraco-cms/2016/custom-list-view-layouts/ I'd guess you'd need to add your dropdown into the listview and then filter the listview result items returned using an AngularJS filter:
Hi Dan,
I did indeed read that article. However I wasn't sure how I can filter the results - Angular JS is not my strong point.
Thanks
Paul
OK, it's not mine either, but I can see that in the example the controller has a value called $scope.items that contains a list of all the items in the listview.
So you could perform a filter on this within the
activate
function, something like:That would just return all the items who have a contentTypeAlias that equals "whatEver". You'd just need to make the comparison value the selected value of your list and then compare it to one of the properties that item has. If it's a custom property then each item has an array of properties for these.
If you add:
to your controller then you can use chrome dev tools console to see all the values. Hope that gives you some help?
Hi Dan,
I've nearly got it working. As my Filter is based on Dropdown Datatype - the values are coming back as Id's, where as the filter is the Name.
I don't suppose you know how to easily output as a name - see this post for a similar scenario - https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/69202-display-dropdown-text-in-list-view
Thanks
Paul
Sorry, Paul, from reading that thread there doesn't seem to be any simple way to do that. Does your filter have to use a Dropdown Datatype - could you not just hardcode a select list?
Unfortunately it has to be dynamic :(
I've managed to get it working, however the filtered results seems to reset themselves when you use the pagination - any thoughts on how I can get around this?
Thanks
Paul
Sorry, Paul, can't think of anything off the top of my head. There is a
umbPagination
directive in Angular with docs here - https://our.umbraco.org/apidocs/ui/#/api/umbraco.directives.directive:umbPaginationHey Paul,
can you share your solution with us? Did you find solution for pagination or you abandon the whole concept and implement different approach.
hello all, if it helps, u can create a custom listview layout ( acurding to the link mentioned Dan Diplo - https://24days.in/umbraco-cms/2016/custom-list-view-layouts/ ).
--- step 1 ---
function getFilterName(item) {
}
--- step 2 ---
go to the html file, go to the second div ( the one with the class "my-songs-layout__cards"
and change the class attribute to :
class="my-songs-layout__card {{item.showOrHide}}"
--- step 3 ---
go to the css file and ad:
.hideItmLst { display: none !important; }
--- step 4 ---
-- by doing all that,. the layout will only show the items with the selected alias you have mentioned in the getFilterName(item) function.
offcurse u can change the display by seeting the css files and the html file but i think u got the idea...
hoped it helps. it worked for me.
P.S - using umbraco 7.5
Hi,
I've implemented this and have it mostly working but can't get it to work with paging.
The issue I'm seeing is because the paged list of items is retrieved and passed to the view you end up with some pages with no items.
Any ideas how to proceed with this?
Thanks
Andy
Andy, did you ever get this working?
O.
Hiya Owain - don't think I ever did get this working!
That's a shame as I've just ran in to the exact same issue.
I've got the listview only showing the items I want to display but they are spread across multiple pages. If the item doesn't appear on page 2 for example, I get a blank page.
Wonder if anyone else can help?
is working on a reply...