Filter Algorithm Improvement












-2















When I select category="books" and partner="amazon" then the Product 4 is showing fine but how to hide Product 1 ?



Please help me so that it can work properly.



 <script>
$('.filter').click(function() {
$('.product').hide();
$('.filter:checked').each(function() {
var filter = $(this).attr('filter');
var data = $(this).attr('data').split(', ');
$.each(data, function(index,value) {
$('.product['+filter+'="'+value+'"]').show();
});
});
});
</script>




<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Category</p>
<div><input class="filter" filter="category" data="boeken" type="checkbox" />books</div>
<div><input class="filter" filter="category" data="spellen" type="checkbox" />games</div>
<div><input class="filter" filter="category" data="andere" type="checkbox" />other</div>

<p>Partners</p>
<div><input class="filter" filter="partner" data="amazon" type="checkbox" />amazon</div>
<div><input class="filter" filter="partner" data="ebay" type="checkbox" />ebay</div>
<div><input class="filter" filter="partner" data="amazon, ebay" type="checkbox" />amazon and ebay</div>
<br>
<div class="products">
<div class="product" category="boeken" partner="amazon" />Product 1</div>
<div class="product" category="spellen" partner="ebay" />Product 2</div>
<div class="product" category="andere" partner="ebay" />Product 3</div>
<div class="product" category="andere" partner="amazon" />Product 4</div>
</div>









share|improve this question























  • If you select books and amazon, then Product4 shouldn't appear...?

    – Rory McCrossan
    Nov 16 '18 at 11:21











  • If I will select books then only Product 1 should be appear but when I select books and amazon then product 4 should be hide. Currenty there are two results are showing.

    – Siddharth
    Nov 16 '18 at 11:27













  • That's the correct logic but your question says the opposite

    – Rory McCrossan
    Nov 16 '18 at 11:35











  • If I select books and amazon then only product 1 should be show. Currently there are two results are showing. See:- (stackoverflow.com/questions/27430989/…)

    – Siddharth
    Nov 16 '18 at 11:37











  • Let me explain you Simply:- If I select country = USA and City = Maryland. Then result should be show according to both match value but currently USA & Maryland all related results are showing.

    – Siddharth
    Nov 16 '18 at 11:41


















-2















When I select category="books" and partner="amazon" then the Product 4 is showing fine but how to hide Product 1 ?



Please help me so that it can work properly.



 <script>
$('.filter').click(function() {
$('.product').hide();
$('.filter:checked').each(function() {
var filter = $(this).attr('filter');
var data = $(this).attr('data').split(', ');
$.each(data, function(index,value) {
$('.product['+filter+'="'+value+'"]').show();
});
});
});
</script>




<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Category</p>
<div><input class="filter" filter="category" data="boeken" type="checkbox" />books</div>
<div><input class="filter" filter="category" data="spellen" type="checkbox" />games</div>
<div><input class="filter" filter="category" data="andere" type="checkbox" />other</div>

<p>Partners</p>
<div><input class="filter" filter="partner" data="amazon" type="checkbox" />amazon</div>
<div><input class="filter" filter="partner" data="ebay" type="checkbox" />ebay</div>
<div><input class="filter" filter="partner" data="amazon, ebay" type="checkbox" />amazon and ebay</div>
<br>
<div class="products">
<div class="product" category="boeken" partner="amazon" />Product 1</div>
<div class="product" category="spellen" partner="ebay" />Product 2</div>
<div class="product" category="andere" partner="ebay" />Product 3</div>
<div class="product" category="andere" partner="amazon" />Product 4</div>
</div>









share|improve this question























  • If you select books and amazon, then Product4 shouldn't appear...?

    – Rory McCrossan
    Nov 16 '18 at 11:21











  • If I will select books then only Product 1 should be appear but when I select books and amazon then product 4 should be hide. Currenty there are two results are showing.

    – Siddharth
    Nov 16 '18 at 11:27













  • That's the correct logic but your question says the opposite

    – Rory McCrossan
    Nov 16 '18 at 11:35











  • If I select books and amazon then only product 1 should be show. Currently there are two results are showing. See:- (stackoverflow.com/questions/27430989/…)

    – Siddharth
    Nov 16 '18 at 11:37











  • Let me explain you Simply:- If I select country = USA and City = Maryland. Then result should be show according to both match value but currently USA & Maryland all related results are showing.

    – Siddharth
    Nov 16 '18 at 11:41
















-2












-2








-2








When I select category="books" and partner="amazon" then the Product 4 is showing fine but how to hide Product 1 ?



Please help me so that it can work properly.



 <script>
$('.filter').click(function() {
$('.product').hide();
$('.filter:checked').each(function() {
var filter = $(this).attr('filter');
var data = $(this).attr('data').split(', ');
$.each(data, function(index,value) {
$('.product['+filter+'="'+value+'"]').show();
});
});
});
</script>




<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Category</p>
<div><input class="filter" filter="category" data="boeken" type="checkbox" />books</div>
<div><input class="filter" filter="category" data="spellen" type="checkbox" />games</div>
<div><input class="filter" filter="category" data="andere" type="checkbox" />other</div>

<p>Partners</p>
<div><input class="filter" filter="partner" data="amazon" type="checkbox" />amazon</div>
<div><input class="filter" filter="partner" data="ebay" type="checkbox" />ebay</div>
<div><input class="filter" filter="partner" data="amazon, ebay" type="checkbox" />amazon and ebay</div>
<br>
<div class="products">
<div class="product" category="boeken" partner="amazon" />Product 1</div>
<div class="product" category="spellen" partner="ebay" />Product 2</div>
<div class="product" category="andere" partner="ebay" />Product 3</div>
<div class="product" category="andere" partner="amazon" />Product 4</div>
</div>









share|improve this question














When I select category="books" and partner="amazon" then the Product 4 is showing fine but how to hide Product 1 ?



Please help me so that it can work properly.



 <script>
$('.filter').click(function() {
$('.product').hide();
$('.filter:checked').each(function() {
var filter = $(this).attr('filter');
var data = $(this).attr('data').split(', ');
$.each(data, function(index,value) {
$('.product['+filter+'="'+value+'"]').show();
});
});
});
</script>




<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Category</p>
<div><input class="filter" filter="category" data="boeken" type="checkbox" />books</div>
<div><input class="filter" filter="category" data="spellen" type="checkbox" />games</div>
<div><input class="filter" filter="category" data="andere" type="checkbox" />other</div>

<p>Partners</p>
<div><input class="filter" filter="partner" data="amazon" type="checkbox" />amazon</div>
<div><input class="filter" filter="partner" data="ebay" type="checkbox" />ebay</div>
<div><input class="filter" filter="partner" data="amazon, ebay" type="checkbox" />amazon and ebay</div>
<br>
<div class="products">
<div class="product" category="boeken" partner="amazon" />Product 1</div>
<div class="product" category="spellen" partner="ebay" />Product 2</div>
<div class="product" category="andere" partner="ebay" />Product 3</div>
<div class="product" category="andere" partner="amazon" />Product 4</div>
</div>






jquery jquery-ui






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 11:19









SiddharthSiddharth

13




13













  • If you select books and amazon, then Product4 shouldn't appear...?

    – Rory McCrossan
    Nov 16 '18 at 11:21











  • If I will select books then only Product 1 should be appear but when I select books and amazon then product 4 should be hide. Currenty there are two results are showing.

    – Siddharth
    Nov 16 '18 at 11:27













  • That's the correct logic but your question says the opposite

    – Rory McCrossan
    Nov 16 '18 at 11:35











  • If I select books and amazon then only product 1 should be show. Currently there are two results are showing. See:- (stackoverflow.com/questions/27430989/…)

    – Siddharth
    Nov 16 '18 at 11:37











  • Let me explain you Simply:- If I select country = USA and City = Maryland. Then result should be show according to both match value but currently USA & Maryland all related results are showing.

    – Siddharth
    Nov 16 '18 at 11:41





















  • If you select books and amazon, then Product4 shouldn't appear...?

    – Rory McCrossan
    Nov 16 '18 at 11:21











  • If I will select books then only Product 1 should be appear but when I select books and amazon then product 4 should be hide. Currenty there are two results are showing.

    – Siddharth
    Nov 16 '18 at 11:27













  • That's the correct logic but your question says the opposite

    – Rory McCrossan
    Nov 16 '18 at 11:35











  • If I select books and amazon then only product 1 should be show. Currently there are two results are showing. See:- (stackoverflow.com/questions/27430989/…)

    – Siddharth
    Nov 16 '18 at 11:37











  • Let me explain you Simply:- If I select country = USA and City = Maryland. Then result should be show according to both match value but currently USA & Maryland all related results are showing.

    – Siddharth
    Nov 16 '18 at 11:41



















If you select books and amazon, then Product4 shouldn't appear...?

– Rory McCrossan
Nov 16 '18 at 11:21





If you select books and amazon, then Product4 shouldn't appear...?

– Rory McCrossan
Nov 16 '18 at 11:21













If I will select books then only Product 1 should be appear but when I select books and amazon then product 4 should be hide. Currenty there are two results are showing.

– Siddharth
Nov 16 '18 at 11:27







If I will select books then only Product 1 should be appear but when I select books and amazon then product 4 should be hide. Currenty there are two results are showing.

– Siddharth
Nov 16 '18 at 11:27















That's the correct logic but your question says the opposite

– Rory McCrossan
Nov 16 '18 at 11:35





That's the correct logic but your question says the opposite

– Rory McCrossan
Nov 16 '18 at 11:35













If I select books and amazon then only product 1 should be show. Currently there are two results are showing. See:- (stackoverflow.com/questions/27430989/…)

– Siddharth
Nov 16 '18 at 11:37





If I select books and amazon then only product 1 should be show. Currently there are two results are showing. See:- (stackoverflow.com/questions/27430989/…)

– Siddharth
Nov 16 '18 at 11:37













Let me explain you Simply:- If I select country = USA and City = Maryland. Then result should be show according to both match value but currently USA & Maryland all related results are showing.

– Siddharth
Nov 16 '18 at 11:41







Let me explain you Simply:- If I select country = USA and City = Maryland. Then result should be show according to both match value but currently USA & Maryland all related results are showing.

– Siddharth
Nov 16 '18 at 11:41














1 Answer
1






active

oldest

votes


















0














you should compose the selector string like this:



$('.filter').click(function() {
$('.product').hide();
$('.filter:checked').each(function() {
var filter = $(this).attr('filter');
var data = $(this).attr('data').split(', ');
var selector = '.product';
$.each(data, function(index,value) {
selector += '['+filter+'="'+value+'"]';
});
$(selector).show();
});
});





share|improve this answer
























  • Thanks for your help but code is not working. It's showing all results.

    – Siddharth
    Nov 16 '18 at 11:34











  • If I select books and amazon then only product 1 should be show. Currently there are two results are showing.

    – Siddharth
    Nov 16 '18 at 11:36











  • Please check this live:- stackoverflow.com/questions/27430989/…

    – Siddharth
    Nov 16 '18 at 11:37












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53336836%2ffilter-algorithm-improvement%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














you should compose the selector string like this:



$('.filter').click(function() {
$('.product').hide();
$('.filter:checked').each(function() {
var filter = $(this).attr('filter');
var data = $(this).attr('data').split(', ');
var selector = '.product';
$.each(data, function(index,value) {
selector += '['+filter+'="'+value+'"]';
});
$(selector).show();
});
});





share|improve this answer
























  • Thanks for your help but code is not working. It's showing all results.

    – Siddharth
    Nov 16 '18 at 11:34











  • If I select books and amazon then only product 1 should be show. Currently there are two results are showing.

    – Siddharth
    Nov 16 '18 at 11:36











  • Please check this live:- stackoverflow.com/questions/27430989/…

    – Siddharth
    Nov 16 '18 at 11:37
















0














you should compose the selector string like this:



$('.filter').click(function() {
$('.product').hide();
$('.filter:checked').each(function() {
var filter = $(this).attr('filter');
var data = $(this).attr('data').split(', ');
var selector = '.product';
$.each(data, function(index,value) {
selector += '['+filter+'="'+value+'"]';
});
$(selector).show();
});
});





share|improve this answer
























  • Thanks for your help but code is not working. It's showing all results.

    – Siddharth
    Nov 16 '18 at 11:34











  • If I select books and amazon then only product 1 should be show. Currently there are two results are showing.

    – Siddharth
    Nov 16 '18 at 11:36











  • Please check this live:- stackoverflow.com/questions/27430989/…

    – Siddharth
    Nov 16 '18 at 11:37














0












0








0







you should compose the selector string like this:



$('.filter').click(function() {
$('.product').hide();
$('.filter:checked').each(function() {
var filter = $(this).attr('filter');
var data = $(this).attr('data').split(', ');
var selector = '.product';
$.each(data, function(index,value) {
selector += '['+filter+'="'+value+'"]';
});
$(selector).show();
});
});





share|improve this answer













you should compose the selector string like this:



$('.filter').click(function() {
$('.product').hide();
$('.filter:checked').each(function() {
var filter = $(this).attr('filter');
var data = $(this).attr('data').split(', ');
var selector = '.product';
$.each(data, function(index,value) {
selector += '['+filter+'="'+value+'"]';
});
$(selector).show();
});
});






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 11:28









simonecoscisimonecosci

82659




82659













  • Thanks for your help but code is not working. It's showing all results.

    – Siddharth
    Nov 16 '18 at 11:34











  • If I select books and amazon then only product 1 should be show. Currently there are two results are showing.

    – Siddharth
    Nov 16 '18 at 11:36











  • Please check this live:- stackoverflow.com/questions/27430989/…

    – Siddharth
    Nov 16 '18 at 11:37



















  • Thanks for your help but code is not working. It's showing all results.

    – Siddharth
    Nov 16 '18 at 11:34











  • If I select books and amazon then only product 1 should be show. Currently there are two results are showing.

    – Siddharth
    Nov 16 '18 at 11:36











  • Please check this live:- stackoverflow.com/questions/27430989/…

    – Siddharth
    Nov 16 '18 at 11:37

















Thanks for your help but code is not working. It's showing all results.

– Siddharth
Nov 16 '18 at 11:34





Thanks for your help but code is not working. It's showing all results.

– Siddharth
Nov 16 '18 at 11:34













If I select books and amazon then only product 1 should be show. Currently there are two results are showing.

– Siddharth
Nov 16 '18 at 11:36





If I select books and amazon then only product 1 should be show. Currently there are two results are showing.

– Siddharth
Nov 16 '18 at 11:36













Please check this live:- stackoverflow.com/questions/27430989/…

– Siddharth
Nov 16 '18 at 11:37





Please check this live:- stackoverflow.com/questions/27430989/…

– Siddharth
Nov 16 '18 at 11:37




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53336836%2ffilter-algorithm-improvement%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python