Igor's previous answer partially reveals the solution.
In general, something like this:
<!-- HTML --> <table> <thead> <tr> <!-- Поисковые поля располагать в шапке таблицы, использовать placeholder --> <th>ID</th> <th><input type="text" class="js-search" data-column="fam" placeholder="Фамилия"></th> <th><input type="text" class="js-search" data-column="im" placeholder="Имя"></th> <th><input type="text" class="js-search" data-column="age" placeholder="Возраст"></th> <th><!-- Остальные поля по шаблону выше --></th> </tr> </thead> <tbody id="result"></tbody> </table>
In the client handler, use the closure to store the search state. Ideally, you should use the debounce function to prevent ajax requests from flying every time you press a button.
// инициализация поиска при готовности разметки $(document).ready(initSearch) function initSearch(){ var fields = {} var $searchFields = $('.js-search') var $result = $('#result') // В обработчике используем функцию задержки обработки события $('.js-search').on('keypress', debounce(function(e){ var $th = $(this) // поле, по которому ищем fields[$th.data('column')] = $th.val() // но на сервер отправляем все заполненные поля $.ajax({ method: 'POST', url: '/search.php', data: fields }).done(function(res){ // в результат вставляем отрендеренный html таблицы $result.html(renderTableResult(res)) }).fail(function(err){ console.log(err) }) },200)) /** * функция формирует разметку результатов поиска * использует не конкатенацию строк, а join массива * @param <array> items - найденные элементы * @return string */ function renderTableResult(items){ // в colspan ставишь количество столбцов if(!items.length) return '<tr><td colspan="3">Не найдено</td></tr>' var html = [] for(var i=0; i < items.length; i++){ html.push('<tr>') // порядковый номер html.push('<td>'+(i+1)+'</td>') // соответсвующие поля html.push('<td>'+ items[i].fam +'</td>') html.push('<td>'+ items[i].im +'</td>') html.push('<td>'+ items[i].age +'</td>') html.push('</tr>') } return html.join('') } } /** * можно и плагин подключить * ВНИМАНИЕ! синтаксис ES2015 * инфо http://jquery.page2page.ru/index.php5/Throttle-debounce * данная функция взята с https://learn.javascript.ru/task/debounce */ function debounce(f, ms) { let timer = null; return function (...args) { const onComplete = () => { f.apply(this, args); timer = null; } if (timer) { clearTimeout(timer); } timer = setTimeout(onComplete, ms); }; }
The initial unfiltered data with pagination is up to you to decide how to insert - directly into the markup when the page loads, or a separate ajax request during initialization
You will receive an object with all the filled fields on the server. It remains only to write a server handler with filtering logic