Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda