Filter by first letter

Get helpful answers from community members using Rubedo 3.x

Filter by first letter

Postby cocqueel » Fri May 05, 2017 2:37 pm

Hello there,
I have a list of content. I'm trying to get results filtered by first letter of my content title, with letters you can click on to filter the results.

I have all my letters displayed with :
Code: Select all
   <ul class="filter">
      <li ng-click="activateLetter('')" ng-class="{'active':activeLetter==''}">TOUS</li>
      <li ng-repeat="letter in alphabet track by $index " ng-click="activateLetter(letter)" ng-class="{'active':letter==activeLetter}">{{letter}}</li>


    </ul>


and this in my ContentListController
Code: Select all
  var str = "abcdefghijklmnopqrstuvwxyz";
  $scope.alphabet = str.toUpperCase().split("");

  $scope.activeLetter = '';

  $scope.activateLetter = function(letter) {


    $scope.activeLetter = letter
  }



I made this filter :
Code: Select all
angular.module("rubedoBlocks").filter('startsWithLettera', function() {
  return function(items, letter) {

    var filtered = [];
    var letterMatch = new RegExp(letter, 'i');
    for (var i = 0; i < items.length; i++) {
      var item = items[i];
      if (letterMatch.test(item.content.fields.text.substring(0, 1))) {
        filtered.push(item);
      }
    }
    return filtered;
  };
});


but when I try to apply it to my Content List template it doesn't work.
Code: Select all
ng-repeat="content in columnContents track by $index | startsWithLettera : activeLetter">


I gest is has to do with
Code: Select all
item.content.fields.text.substring
but I don't know what to put there. I tried everything (well, not everything, because it is still not rendering anything)...
Please can I have some help ?
Thank you,
Emmaunelle
cocqueel
Member
 
Posts: 12
Joined: Wed Feb 08, 2017 3:43 pm

Re: Filter by first letter

Postby nicolas.rhone » Fri May 05, 2017 5:44 pm

Hello,

You might try to do like that :

ng-repeat="content in columnContents | startsWithLettera : activeLetter track by $index"> with track by $index after the filter.
nicolas.rhone
Member
 
Posts: 81
Joined: Tue Sep 16, 2014 3:24 pm
Location: Lyon

Re: Filter by first letter

Postby cocqueel » Tue May 09, 2017 9:48 am

I didi it, and still nothing. I think the problem is from my filter, there :
Code: Select all
if (letterMatch.test(item.content.fields.text.substring(0, 1))) {
        filtered.push(item);
      }

It has to filter from my text field, but I think it doesn't know where to look.
cocqueel
Member
 
Posts: 12
Joined: Wed Feb 08, 2017 3:43 pm


Return to Rubedo V3 : Q&A

Who is online

Users browsing this forum: No registered users and 4 guests

cron