Preethi Jain Preethi Jain - 2 years ago 61
Javascript Question

How to write a table filter in this case

I have got a table , and also a filter for Quantity column

My requirement is that , i want to display only the contents that are greater than the entered in the filter quanity column

This is my logic :

$(document).ready(function () {
(function ($) {
$('#filter').keyup(function () {
var rex = new RegExp($(this).val(), 'i');
$('#myTable tr').hide();
$('#myTable td:eq(2)').filter(function () {
return rex.test($(this).text());

please let me know how to do this .

Answer Source

You can do it like following.

$('#filter').keyup(function() {
    var quantiy = +$(this).val(); //+ to convert string to number

    var tr = $('#myTable tbody tr');
    tr.filter(function() {
        return +$('td:eq(3)', this).text() > quantiy;  //select quantity column by '$('td:eq(3)', this)'


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download