Disable filtering on a column in ng-grid

我只是一个虾纸丫 提交于 2019-12-24 15:21:25

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/25529493/disable-filtering-on-a-column-in-ng-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!