0

グリッド ビューのすべての列をテキスト ボックスでフィルター処理するためにこのコードを試しましたが、グリッドの最後の列をフィルター処理するだけです。どうすれば変更できますか?私のコードで何が間違っていますか? 私の最初の列は 2 で、最後の列は 4 です。私の for ループは 2 で始まり、4 で終わりましたが、この ""(i=2;i<4;i++) を試すと、インデックスが 3 の列が表示されます。

 $(document).ready(function () {
        // Client Side Search (Autocomplete)
        // Get the search Key from the TextBox
        // Iterate through the 1st Column.
        // td:nth-child(1) - Filters only the 1st Column
        // If there is a match show the row [$(this).parent() gives the Row]
        // Else hide the row [$(this).parent() gives the Row]

        $('#filter').keyup(function (event) {
            var searchKey = $(this).val();
            for (i =2; i<5; i++) {
                $("#gvwHuman_ctl00 tr  td:nth-child(" + i + ")").each(function () {
                // $("#gvwHuman_ctl00 tr td:nth-child(" + i + ")").each(function () {
                    var cellText = $(this).text();
                    if (cellText.indexOf(searchKey) >= 0) {
                        $(this).parent().show();
                    } else {
                        $(this).parent().hide();
                    }
                });
            }
        });
    });
4

1 に答える 1

1

問題は、行のセルごとに、行を表示または非表示にすることです。したがって、最後の 1 つだけが重要です。

あなたはこれを行うことができます:

       // 1 : hide all rows
       $("#gvwHuman_ctl00 tr").hide();

       // 2 : show the row if there is one match
       for (i =2; i<5; i++) {
            $("#gvwHuman_ctl00 tr  td:nth-child(" + i + ")").each(function () {
            // $("#gvwHuman_ctl00 tr td:nth-child(" + i + ")").each(function () {
                var cellText = $(this).text();
                if (cellText.indexOf(searchKey) >= 0) {
                    $(this).closest('tr').show();
                }
            });
        }
于 2013-05-25T12:22:46.590 に答える