Reputation: 607
There is example: http://jsfiddle.net/pVP6w/
$("#options1").change(function() {
$("#filter1").keyup();
});
$("#filter1").keyup(function () {
var filter1 = $("#filter1").val();
var tr = $('tr').not(":nth-child(1)");
if (!filter1.length) return tr.show();
tr.hide().filter(function () {
var t = $('.wys', this).attr('data-wys');
return operators[$("#options1").val()](t, parseInt(filter1));
}).show();
});
If you click on button you see a some forms. And 'td' set attr to optimize searching in next step.
First input change column Value, Second input change column Value2, Third input change column Value3, Last is no important.
How to connect all form to get one common result? Now if i key up any form result is getting from all 'tr'
Upvotes: 0
Views: 98
Reputation: 6525
I optimized your code as you said, Demo JSFIDDLE
$(document).ready(function() {
function eachcolom($that){
$that.each(function() {
$(this).attr('data-wys',parseFloat($(this).text()));
});
}
$("#inputs").hide();
$("#detailed").click(function(){
$("#inputs").toggle();
eachcolom($('.wys'))
eachcolom($('.ctr'))
eachcolom($('.ok'))
});
var operators = {
'equal': function(a, b) { return a == b },
'notequal': function(a, b) { return a != b },
'more': function(a, b) { return a > b },
'less': function(a, b) { return a < b }
};
function allForm($that, filt, ass, ty){
var filter1 = $(filt).val();
var tr = $('tr').not(":nth-child(1)");
if (!filter1.length) return tr.show();
switch(ty){
case 'f':
filter1 = parseFloat(filter1);
break;
case 'i':
filter1 = parseInt(filter1);
//alert(filter1)
break;
};
tr.hide().filter(function () {
var t = $("."+ass.attr('class'), this).attr('data-'+ass.attr('class'));
console.log(operators[$that.val()](t, filter1))
return operators[$that.val()](t, filter1);
}).show();
}
$("#options1").change(function() {
//allForm($(this),$('#filter1'))
$("#filter1").keyup();
});
$("#filter1").keyup(function () {
//alert('')
allForm($(this).prev('select'), this, $('.wys'), 'i')
});
$("#options2").change(function() {
$("#filter2").keyup();
});
$("#filter2").keyup(function () {
allForm($(this).prev('select'), this, $('.ctr'), 'f')
});
$("#options3").change(function() {
$("#filter3").keyup();
});
$("#filter3").keyup(function () {
allForm($(this).prev('select'), this, $('.ok'), 'f')
});
});
Upvotes: 1