Multiple Filters
$(document).ready(function () {
ManageRadioButtons();
numerizeRows();
$('[data-toggle="tooltip"]').tooltip();
});
jQuery.expr[':'].icontains = function (a, i, m) {
return jQuery(a).text().toUpperCase()
.indexOf(m[3].toUpperCase()) >= 0;
};
$("#searchInputResponsibility").keyup(function () {
if (checkMultiple() == true) {
filterMultiple();
return true;
}
var data = this.value.split(" ");
var currentRow = $("#fbody").find("tr").not('.H').not('.thead');
if (this.value == "") {
currentRow.show();
return;
}
//hide all the rows
currentRow.hide();
currentRow.filter(function (i, v) {
var $t = $(this).find("td:eq(0)");
for (var d = 0; d < data.length; ++d) {
if ($t.is(":icontains('" + data[d] + "')")) {
return true;
}
}
return false;
})
.show();
}).focus(function () {
this.value = "";
$(this).css({
"color": "black"
});
$(this).unbind('focus');
});
function numerizeRows() {
var eachRow = $("#fbody").find("tr").not('.H').not('.thead');
var start = 1;
eachRow.each(function () {
$(this).children('td:eq(1)').html(start);
start = start + 1;
});
};
$("#searchInputTask").keyup(function () {
if (checkMultiple() == true) {
filterMultiple();
return true;
}
var data = this.value.split(" ");
var currentRow = $("#fbody").find("tr").not('.H').not('.thead');
if (this.value == "") {
currentRow.show();
return;
}
//hide all the rows
currentRow.hide();
currentRow.filter(function (i, v) {
var $t = $(this).find("td:eq(2)");
for (var d = 0; d < data.length; ++d) {
if ($t.is(":icontains('" + data[d] + "')")) {
return true;
}
}
return false;
})
//show the rows that match.
.show();
}).focus(function () {
this.value = "";
$(this).css({
"color": "black"
});
$(this).unbind('focus');
});
$("#searchInputNotes").keyup(function () {
if (checkMultiple() == true) {
filterMultiple();
return true;
// return;
}
var data = this.value.split(" ");
var currentRow = $("#fbody").find("tr").not('.H').not('.thead');
if (this.value == "") {
currentRow.show();
return;
}
//hide all the rows
currentRow.hide();
currentRow.filter(function (i, v) {
var $t = $(this).find("td:eq(3)");
for (var d = 0; d < data.length; ++d) {
if ($t.is(":icontains('" + data[d] + "')")) {
return true;
}
}
return false;
})
//show the rows that match.
.show();
}).focus(function () {
this.value = "";
$(this).css({
"color": "black"
});
$(this).unbind('focus');
});
function checkMultiple() {
var dataP = $("#searchInputResponsibility").val().split(" ");
var dataR = $("#searchInputTask").val().split(" ");
var dataI = $("#searchInputNotes").val();
if (dataI != "" && dataR != "") return true;
if (dataI != "" && dataP != "") return true;
if (dataP != "" && dataR != "") return true;
return false;
};
function filterMultiple () {
var dataI = $("#searchInputNotes").val().split(" ");
var dataR = $("#searchInputTask").val().split(" ");
var dataP = $("#searchInputResponsibility").val().split(" ");
var allRows = $("#fbody").find("tr").not('.H').not('.thead');
if (dataI == "" && dataR == "" && dataP == "") {
allRows.show();
return;
}
//hide all the rows
allRows.hide();
allRows.filter(function (i, v) {
var $v = $(this).find("td:eq(0)");
var $u = $(this).find("td:eq(1)");
var $t = $(this).find("td:eq(2)");
if (dataI != "" && dataR != "" && dataP != "") {
for (var p = 0; p < 2; ++p) {
if ($v.is(":icontains('" + dataP[p] + "')") && ($u.is(":icontains('" + dataR[p] + "')")) && $t.is(":icontains('" + dataI[p] + "')") ) {
return true;
}
}
}
if (dataI != "" && dataR != "" && dataP == "") {
for (var p = 0; p < 2; ++p) {
if (($u.is(":icontains('" + dataR[p] + "')")) && $t.is(":icontains('" + dataI[p] + "')")) {
return true;
}
}
}
if (dataI == "" && dataR != "" && dataP != "") {
for (var p = 0; p < 2; ++p) {
if (($u.is(":icontains('" + dataR[p] + "')")) && $v.is(":icontains('" + dataP[p] + "')")) {
return true;
}
}
}
if (dataI != "" && dataR == "" && dataP != "") {
for (var p = 0; p < 2; ++p) {
if (($t.is(":icontains('" + dataI[p] + "')")) && $v.is(":icontains('" + dataP[p] + "')")) {
return true;
}
}
}
if (dataI != "" && dataR != "" && dataP == "") {
for (var p = 0; p < 2; ++p) {
if (($u.is(":icontains('" + dataR[p] + "')")) && $t.is(":icontains('" + dataI[p] + "')")) {
return true;
}
}
}
return false;
})
.show();
};
$("input[type='radio']").change(function () {
ManageRadioButtons();
});
function ManageRadioButtons() {
$("#searchInputResponsibility").val('');;
$("#searchInputTask").val('');;
$("#searchInputNotes").val('');;
var selection = $('input[name=env]:checked').val();
var currentRow = $("#fbody").find("tr").not('.H');
currentRow.hide();
if (selection == "QA") {
var QARows = $("#fbody").find("tr.Q");
QARows.show();
} else {
var PRows = $("#fbody").find("tr.P");
PRows.show();
}
};
Comments