java - Multiple search from HTML table -
function dosearch() { var searchtext = document.getelementbyid('searchterm').value; var targettable = document.getelementbyid('datatable'); var targettablecolcount; // loop through table rows. (var rowindex = 0; rowindex < targettable.rows.length; rowindex++) { var rowdata = ''; // column count header row. if (rowindex == 0) { targettablecolcount = targettable.rows.item(rowindex).cells.length; continue; //do not execute further code header row. } // process data rows. (rowindex >= 1) (var colindex = 0; colindex < targettablecolcount; colindex++) { rowdata += targettable.rows.item(rowindex).cells.item(colindex).textcontent; } // if search term not found in row data hide row, else show. if (rowdata.indexof(searchtext) == -1) targettable.rows.item(rowindex).style.display = 'none'; else targettable.rows.item(rowindex).style.display = 'table-row'; } }
this code working great searching 1 keyword, want search multiple keywords separated semicolon (;).
first make function dosearch parameter. instead of :
function dosearch() { var searchtext = document.getelementbyid('searchterm').value;
put
function dosearch(searchvalue, rows) {...}
then
var keywords = document.getelementbyid('searchterm').value.split(';');
and loop on function dosearch(keyword[index], rowindexes);
to contain keywords
let function dosearch() return array rowindexes match. , pass next call, until keywords finish.
the last result rowindexes match keywords.
Comments
Post a Comment