Как отфильтровать таблицу JS, используя несколько входов - PullRequest
0 голосов
/ 31 мая 2018

Я пишу приложение на c #.Я должен фильтровать таблицу JS, используя несколько входов.Когда я вписываю что-то только в один ввод, он работает нормально, но если я хочу найти таблицу, например, по «Сервисной цене» и «Частям по цене», он ничего не находит.

    <form id="search-repairs">
    <p>
        Service Price : <input type="text" id="searchServicePrice" class="searchInput" onkeyup="searchingEngine(3)" />
        Parts Price : <input type="text" id="searchPartsPrice" class="searchInput" onkeyup="searchingEngine(2)" />
        Summary Price : <input type="text" id="searchBySumPrice" class="searchInput" onkeyup="searchingEngine(5)" />
        Date : <input type="text" id="searchDate" class="searchInput" onkeyup="searchingEngine(0)" />

    </p>
</form>



<table id="table" class="table table-striped table-hover">
    <thead>
        <tr>
            <th>
                Date
            </th>
            <th>
                Description
            </th>
            <th>
                PartsPrice
            </th>
            <th>
                Price
            </th>
            <th>
                ServicerId
            </th>
            <th>
                summaryPrice
            </th>
        </tr>
    </thead>
    <tbody id="searchBody">

        @foreach (var item in Model)
        {
            var price = item.Price;
            var partsPrice = item.PartsPrice;
            var sum = price + partsPrice;
            <tr>

                <td>
                    @Html.DisplayFor(modelItem => item.Date)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Description)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.PartsPrice)
                </td>
                <td name="price">
                    @Html.DisplayFor(modelItem => item.Price)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ServicerId)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => sum);
                </td>


            </tr>
        }

    </tbody>
</table>

А вот мой код дляОтфильтруйте эту таблицу.Это простой код JavaScript.Я думаю, что что-то не так в переменной фильтра.Я перепробовал много разных решений, но он не хотел работать ни в коем случае.

function searchingEngine(col) {
    var table, trs, searchByPrice, searchByPartsPrice, searchByDate, searchBySumPrice, filter, i, td;
    table = document.getElementById("table");
    trs = table.getElementsByTagName("tr");


    searchByPrice = document.forms['search-repairs'].querySelector("#searchServicePrice");
    searchByPartsPrice = document.forms['search-repairs'].querySelector("#searchPartsPrice");
    searchByDate = document.forms['search-repairs'].querySelector("#searchDate");
    searchBySumPrice = document.forms['search-repairs'].querySelector("#searchBySumPrice");

    filter = searchByPrice.value.toUpperCase() || searchByPartsPrice.value.toUpperCase() ||
        searchByDate.value.toUpperCase() || searchBySumPrice.value.toUpperCase();
    for (i = 0; i < trs.length; i++) {
        td = trs[i].getElementsByTagName("td")[col];
        if (td) {
            if (td.textContent.toUpperCase().indexOf(filter) > -1) {
                trs[i].style.display = "";


            } else {
                trs[i].style.display = "none";


            }

        }

    }

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...