Coder Social home page Coder Social logo

Comments (7)

MrWook avatar MrWook commented on July 22, 2024 1

Hello @dhavebarsalote96636677,

the stSearch directive is using a normal search. That means if you use the "Global search" it will search for the text "acc 33" in any of the column. Therefore for the Smart-Table the given text is nowhere to be found.
What you want here is that the "Global search" split the text at spaces and search in every column with every item from the splited text.
This kind of search is something that you need to do on your own. You can extend the stSearch directive or create a new one for this purpose.

But just a info you can create a column based search for every column

from smart-table.

dhavebarsalote96636677 avatar dhavebarsalote96636677 commented on July 22, 2024

Hello @MrWook ,
Yes indeed i need to create my own in order to achieve this. Why I am requiring it to act in this behavior, is because some of our users search for word like : "Bosch diy washer" when they happen to forgot the exact words of an item, when having the original value of the column as : " BOSCH AQUATAKÂ DIY HIGHÂ PRESSURE WASHER AQT". (I highlighted the search word the user searched).
What I have tried so far was:
altering the smart-table.js search() function when receiving the input value.
Dhave, [16.05.18 08:41]

    this.search = function search(input, predicate, comparator) {
      var predicateObjects;
      var prop;

      var strVar = input.toLowerCase().split(/\s+/);

      var predicateObjects = tableState.search.predicateObject || {};
      prop = predicate ? predicate : '$';

      for (var i = 0; i < strVar.length; i++) {
        $parse(prop).assign(predicateObjects, strVar[i]);
        // to avoid to filter out null value  
          if (!strVar) {
          deepDelete(predicateObjects, prop);
        }
      }       
      tableState.search.predicateObject = predicateObjects;
      tableState.pagination.start = 0;
      return this.pipe();
    };

That's all i have for now, it can now search for keymatch. The problem is it can't watch previous word to strictly filter the result waiting for the next key.

This guys, get's it but I wan't his logic applied to smart-table stSearch.
https://stackoverflow.com/questions/42023387/angular-smart-search-on-wildcard#

from smart-table.

MrWook avatar MrWook commented on July 22, 2024

Oh boi i'm sorry i forgot there is a directive st-set-filter for this kind of case. Here is the filter for a global search.

app.filter('filterByObjectName', function ($filter) {
	return function(input, predicate){
		var returnArray = [];
			angular.forEach(predicate, function(value, key){
				var searchTextSplit = value.toLowerCase().split(' ');
				for (var x = 0; x < input.length; x++) {
					var count = 0;
					for (var y = 0; y < searchTextSplit.length; y++) {
						let propertyValue = input[x][key];
						if (propertyValue.toLowerCase().indexOf(searchTextSplit[y]) !== -1) {
							count++;
						}
					}
					if (count == searchTextSplit.length) {
						returnArray.push(input[x]);
					}
				}
			});
		return returnArray;
	}
});

After that you need to add the filter to the directive:
<table st-table="displayCollection" st-set-filter="filterByObjectName" class="table table-striped">

from smart-table.

dhavebarsalote96636677 avatar dhavebarsalote96636677 commented on July 22, 2024

Thank you @MrWook, I am able to get the expected result from the logic above, I just replaced
let propertyValue = input[x][key];
to
let propertyValue = input[x].ItemName;

Then, right now if I leave the st-Search field empty, the table has no data.

from smart-table.

dhavebarsalote96636677 avatar dhavebarsalote96636677 commented on July 22, 2024

Why all of a sudden after making it work, it just out of no where my propertyValue becomes Null?

from smart-table.

dhavebarsalote96636677 avatar dhavebarsalote96636677 commented on July 22, 2024

Maybe you did something not right and resulted to incorrectiveness of the programmability of your coding.

from smart-table.

MrWook avatar MrWook commented on July 22, 2024

You can't just copy paste something from the internet you need to adjust it to your needs.
I wrote that this filter is only for the global search. If you use ItemName(probably your own property from your data) instead of key this won't work anymore because if you search for something and don't have the property ItemName, propertyValue will be Null.
If you just changed the value key into ItemName thats okey but don't try to use a variable as a JavaScript property that won't work. It need to be called as an array.
input[x][ItemName];

from smart-table.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.