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

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

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 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