Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
Show only unique search results in html Datatable

I have created a CRUD web app based on Googlesheet. I'm getting duplicate search results when I try to search through multiple rows and columns of the html datatable in the web App. This happens when search test matches data in the multiple columns of the same row. How can I get it to display only unique results? How can alter my code to search through only first 3/4 columns?

Example of duplicate search results in the web app search input: test:

Example of duplicate search results in the webapp- search input: test

Google script code:

function searchData(formObject){  
  var result = [];
  if(formObject.searchtext){//Execute if form passes search text
      var data = Sheets.Spreadsheets.Values.get(globalVariables().spreadsheetId, globalVariables().dataRange).values;
      for(var i=0;i<data.length;i++){
        for(var j=0;j<data[i].length;j++){
          if(data[i][j].toLowerCase().search(formObject.searchtext.toLowerCase())!=-1){
            result.push(data[i])
          }
        }
      }
  }
  return result;
}

JavaScript

function handleSearchForm(formObject) {
    google.script.run.withSuccessHandler(createTable).searchData(formObject);
    document.getElementById("search-form").reset();
  }
<!-- SEARCH FORM-->
<form id="search-form" class="form-inline" onsubmit="handleSearchForm(this)">
  <div class="form-group mx-sm-3 mb-2">
    <label for="searchtext" class="sr-only">Search Text</label>
    <input type="search" class="form-control form-control-sm" id="searchtext" name="searchtext" placeholder="Search">
  </div>
  <button type="submit" class="btn btn-sm btn-primary mb-2">Search</button>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

this is the part of the script that searches through all the columns in one row:

    for(var j=0;j<data[i].length;j++){
      if(data[i][j].toLowerCase().search(formObject.searchtext.toLowerCase())!=-1){
        result.push(data[i])
      }
    }

If you would like to search just by, for example, the first column, you could replace that code with:

const COLUMN_INDEX = 0;
if(data[i][COLUMN_INDEX].toLowerCase().search(formObject.searchtext.toLowerCase())!=-1){
  result.push(data[i])
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda