-
Notifications
You must be signed in to change notification settings - Fork 897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multifilter functionality added #139
base: master
Are you sure you want to change the base?
Conversation
Would you please elaborate on what do u mean by multifilter? and how to implement that. 1- filter items purchased today, then i want to sort them their price (this works fine). So, how can I keep adding filters instead of apply a new one every time? n.b after looking at the code, it seems filter works on this.items, while i want it to work on this.matchingITems. Thanks. |
I am really struggling with multiFiltering. Do you have any simple example page? please? |
@shohagbhuiyan: it's quite easy once you figure it out. In other words, create your own array and whenever you want to apply a filter added the filter function to the array and then pass the whole array to list.js filter function, it will detect whether u r passing a a single function or an array, if array is being passed, then it will loop thru it and apply each function. Basically that what i did. One more thing, if you want to remove a certain filter, delete it from the array then pass the array again so it will apply other filters. Hope it's clear enough. |
Hi @mjoraid, thanks for the reply. But do you have any example or demo link? It will help me a lot. Thanks. |
Well, I think I used it somewhat like this:
|
The purpose for my use case, was that I had a left column in my UI, where I would enable/disable different kind of filters. So I dynamically populated an array of filter-functions based on which ones were enabled, and the state of those custom filters. This array gets passed to filter, and voila! |
👍 to merging this. |
Any chance this will get merged, perhaps into v1.2.0? I'm happy to help if that's all we're waiting for, @javve. |
Just to help new comers, this what i did. Im sure someone can do better. From my class object, I made a few functions to use list.js library. Code samples like: //this function will get the value from html dom when the user choose to filter a range
LobbyClass.prototype.filterInt = function(dom_class, min, max)
{
min = parseInt(min);
max = parseInt(max);
//this filter function will be store in array to be passed to list.js later on
var filterFunction = function(item) {
var intVal = parseInt(item.values()[dom_class]);
if (intVal >= min && intVal <= max) {
return true;
} else {
return false;
}
};
this.addFilterAndApply(dom_class, filterFunction);//build up filters so we can have multiple filters
};
LobbyClass.prototype.addFilterAndApply = function(type, filter)
{ //override previous function from same type, one filter for each type.
if (type && filter)
{
this.filters[type] = filter;
}
var allFilters = this.getFilters();
if (allFilters.length > 0)
{
this.filterComp.filter(allFilters);//pass all filters to be applied.
this.checkTableRows();// to dsiplay message if no data found.
}
};
LobbyClass.prototype.getFilters = function(name)
{
if (name)
{
return this.filters[name];
}
else
{
//convert object to array
var filters_arr = [];
$.each(this.filters, function(index, data) {
filters_arr.push(data);
});
return filters_arr;
}
}; |
+1! I manually merged this in and didn't see any conflicts. Not sure what that notification from GitHub (below) means. Please merge this in @javve :) |
@cbier how and where did you merge this? |
The Code-Change in the first Posting has a small bug:
If i write jo in the first field, filtering is ok (Jonny Stromberg, Jonas Arnklint). |
@sandersu I manually added the changes to my local list.js |
Any chance this could be merged in the near future or should I look for alternatives? |
I wanted to add multiple filters to the list, so this is how I added that functionality...