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

274
Visualizações
JQuery TablEdit add editable column dropdown option from database

I have a problem with TableEdit

This is in the documentation I read:

// Example #2
columns: {
    // Column used to identify table row.
    // [column_index, input_name]
    identifier: [0, 'id'],
    // Columns to transform in editable cells.
    // [[column_index, input_name], [column_index, input_name, select_options]]
    editable: [[1, 'car'], [2, 'color', '{"1": "Red", "2": "Green", "3": "Blue"}']]
}

In the editable key, the second array contains a json-like string that renders as a dropdown list when I press the edit button.

My question is, how do I make that json-like string dynamically?

I have an ajax request that returns a list of departments. I want to pass those departments into that editable column.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In my opinion you can try call ajax request to get a list of department. After that create tabledit. You can try like this:

Javascript:

After ajax request done. You can use JSON.stringify() to onvert a JavaScript object into a string.

function initTableEdit() {
     $.post('select-data.php')
          .done(function (res) {
               let data = [[1, 'First Name'], [2, 'Last Name'], [3, 'Username', JSON.stringify(res)]]
               creatTableEdit(data)
          })
 }

function creatTableEdit(data) {
     $('#example2').Tabledit({
          editButton: true,
          removeButton: false,
          columns: {
              identifier: [0, 'id'],
              editable: data
          }
     });
}

PHP: select-data.php

<?php
header('Content-Type: application/json');
echo json_encode([
    1 => '@mdo', 2 => '@fat', 3 => '@twitter',
]);

die();
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