M
M
mortyyyyy2015-10-19 16:39:19
JavaScript
mortyyyyy, 2015-10-19 16:39:19

How to implement search with table sorting?

There is a table in the first column of which the row number is indicated Implemented a search in the table with cell highlighting in which a match was found and a row in which a match was found goes up.

function filter(row) {
            var val = _input.value.toLowerCase();
            Arr.forEach.call(row.cells, function (cell) {
                if (cell.textContent.toLocaleLowerCase().indexOf(val) !== -1 && val) {
                    addClass(cell);
                    row.parentNode.insertBefore(row,row.parentNode.rows[0]);
                }
                else {
                    removeClass(cell)
                }
            });
        }

The problem is that all the rows are shuffled and the rows in which there are no matches are out of order. How to make rows in which there are no matches stand in order?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Golubev, 2015-10-19
@Piocan-Alex

List.js is a simple, lightweight and efficient script to help you .

K
Konstantin Gromov, 2015-10-20
@Pathgk

jsfiddle.net/k7d1w9vo
Hardly what you need, but I described the idea. If IE9 is important, then it is worth replacing all uses of classList with polyfills, and remember that the input event does not fire in it when backspace is clicked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question