Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!