lorenzofox3 / Smart-Table

Code source of Smart Table module: a table/grid for Angularjs
http://lorenzofox3.github.io/smart-table-website/
1.8k stars 512 forks source link

Is there are a way for a strict search in custom directive? #741

Open kyrodabase opened 7 years ago

kyrodabase commented 7 years ago

Hi,

Great lib! :)

Is there are a way to match the exact search term instead of a substring? Currently if I search for ID = 4, the search function returns ID = 4 and ID = 4000, ID = 4001 etc. Here is a code snippet:

` .directive("customWatchFilters", function () {

return {
  restrict: "A",
  require: "^stTable",
  link: function (scope, element, attrs, ctrl) {
    scope.$watchCollection(attrs.customWatchFilters, function (filters) {

      ctrl.tableState().search.predicateObject = {};

      angular.forEach(filters, function (val, filter) {
        if (angular.isUndefined(val) || val === null) {
          return;
        }

        ctrl.search(val.toString(), filter);
      });

      ctrl.pipe();

    });
  }
};

});`

Please advise

lorenzofox3 commented 7 years ago

you have on the documentation website section "strict mode filtering"

kyrodabase commented 7 years ago

I have seen it, none of the examples include a way to do it in custom directive.

lorenzofox3 commented 7 years ago

you are right, it might be easier to pass a stricmode flag here to follow the same signature than angular filter filter.

You can submit a PR, or I ll do it over the week end

kyrodabase commented 7 years ago

Thanks!

lorenzofox3 commented 7 years ago

Hi, I looked into it and found out that the strict flag you pass to the angular filter filter would be global meaning you can not do a strict search on a column and a regular search on another, unless you use a custom filter. What do you think ?

kyrodabase commented 7 years ago

I think global filter would be an option, at least in our case.