Comments (7)
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.
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.
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.
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.
Why all of a sudden after making it work, it just out of no where my propertyValue becomes Null?
from smart-table.
Maybe you did something not right and resulted to incorrectiveness of the programmability of your coding.
from smart-table.
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)
- Natural sort of alpha numeric string HOT 1
- st-sort-default="true" is not working fine with custom sort HOT 6
- st-ratio can not be declared as a function HOT 1
- st-sort-default="true" not working when table first loads. HOT 2
- Delete row after searching HOT 1
- When I debug st-table safeCopy object it returns empty array. HOT 1
- sever side pagination
- Paginated data updates HOT 1
- get filter date in table using start and end date in angular 5 HOT 1
- Smart table with two custom date filters HOT 1
- Virtualisation feature
- Manipulate the current page within a controller for pagination
- Serverside pagination issue
- Smart table documentation website melts my computer HOT 1
- aria-sort order is wrong
- Question: how to programmatically go to a specific page?
- Custom filtering on single column HOT 1
- How to pass argument with st-pipe
- st-sort does not work when start with number.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from smart-table.