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

113
Visualizações
Jquery datatables custom search function on JSON data

This datatable search function looks within a data field gates which is represented in JSON as

{ "completed": [], "na": [], "open": []}

The filter function is trying to look within a the "completed" key of the gates object for an for an entry matching "TestGate", which indicates whether the testing state was completed or not. We use this result for the search filter (checkbox toggle):

$.fn.dataTable.ext.search.push(
        function (settings, data, dataIndex) {
            if ($("#checkboxRRComplete").is(":checked")) {
                let gates = data[5] || {}
                console.log(gates) \\"[obj Object]" need gate to be a JS object
                return gates.completed.includes("TestGate")
            }
            return true
        }
    )

The problem here is that function above the data input is casted to a string. So in the function scope it is "[obj Object]" and the object fields are no longer accessible. Is there a way to create custom search criteria that is JSON object friendly?

NOTE: Since running into this issue I decided to just add another field to my ajax request response to be used for filtering. However, I am still wondering if there is a better way to do this by searching objects.

about 4 years ago · Juan Pablo Isaza
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