I have made a table here : fiddle but I seem unable to get my table filter to work. What I tried to do was create a menu at the top where a specific filter would only show those rows. I tried to use .Data
for this.
Filter Row Script
$('.filterMenu a').on('click', function(e){
e.preventDefault();
var c= $(this).data('qtype');
$('#questTable')[0].className = c;
});
Row Hover Script
$(document).ready(function() {
$('.table-row').hover(function() {
$(this).addClass('current-row');
}, function() {
$(this).removeClass('current-row');
});
});
Row hide Script
$(document).ready(function() {
$('tr')
.filter(':has(:checkbox:checked)')
.addClass('selected')
.end()
.click(function(event) {
if (event.target.type !== 'checkbox') {
$(':checkbox', this).trigger('click');
}
})
.find(':checkbox')
.click(function(event) {
$(this).parents('tr:first').toggleClass('selected');
});
});
I have made a table here : fiddle but I seem unable to get my table filter to work. What I tried to do was create a menu at the top where a specific filter would only show those rows. I tried to use .Data
for this.
Filter Row Script
$('.filterMenu a').on('click', function(e){
e.preventDefault();
var c= $(this).data('qtype');
$('#questTable')[0].className = c;
});
Row Hover Script
$(document).ready(function() {
$('.table-row').hover(function() {
$(this).addClass('current-row');
}, function() {
$(this).removeClass('current-row');
});
});
Row hide Script
$(document).ready(function() {
$('tr')
.filter(':has(:checkbox:checked)')
.addClass('selected')
.end()
.click(function(event) {
if (event.target.type !== 'checkbox') {
$(':checkbox', this).trigger('click');
}
})
.find(':checkbox')
.click(function(event) {
$(this).parents('tr:first').toggleClass('selected');
});
});
Share
Improve this question
edited Aug 13, 2015 at 7:19
Alexis Tyler
9686 gold badges32 silver badges51 bronze badges
asked Aug 13, 2015 at 6:18
RenierRenier
731 silver badge10 bronze badges
1 Answer
Reset to default 8Here is a working example
The basic idea is to first hide all rows and then recursively show them, when they match your criteria.
Find all tr
in tbody
and hide them
var trs = $("#questTable").find("tbody tr");
trs.hide();
I would make use of the filter function
.filter(function (i, v) {})
to check if the row should be shown.
trs.filter(function (i, v) {
if ($(this).data("qtype") == c) {
return true;
}
if(c=="all"){
return true;
}
return false;
})
//just show the row if it fits the criteria
.show();
Additionally I have fixed your typo msq -> mcq for the data-qtype in tr
Edit: Just updated the fiddle with more ments and fixed the thead area
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745358702a4624261.html
评论列表(0条)