1

I want ng-grid not to search based on specific columns, but I do want those columns to still be sortable.

Is there a way to accomplish this?

abyx
  • 69,862
  • 18
  • 95
  • 117

1 Answers1

2

Sorry I'm late, meetings all day:-\ Got this running with a modfied version of my answer example from here.

This one is based on the official server sided pagination example from here.

I changed the code in $scope.getPagedDataAsync to include this filtering function:

  if (searchText) {
    var ft = searchText.toLowerCase();
    data = $scope.longData.filter(function(item) {
      var si=JSON.stringify(item.allowance).toLowerCase()+JSON.stringify(item.paid).toLowerCase();
      if (si.indexOf(ft)!=-1){
        return item;
      };
    });

This will generate a string from the column data fields allowance and paid, ingores the name column, and searches the generated string for any occurrence of the search text. Add more colums to your liking.

If searchtext is found anywhere in the string the item is returned to ng-grid.

This is case insensitive, hence the toLowerCase() part.

Find a working Plunker here.

Community
  • 1
  • 1
mainguy
  • 8,283
  • 2
  • 31
  • 40
  • Thank you for this answer. This does seem to solve the issue, but at the cost of implementing filtering all by myself and having to sync this code whenever we add/remove/change a column. I'll leave this question open for a bit longer – abyx Aug 31 '14 at 04:44
  • Maybe give the filterbar plugin a try: http://plnkr.co/edit/LRdkiRzFjoe8LFK7Sxt7?p=preview I disabled the age filter in this example. – mainguy Sep 01 '14 at 11:34