lightswitch05 / table-to-json

Serializes HTML tables into JSON objects.
http://lightswitch05.github.io/table-to-json/
MIT License
756 stars 172 forks source link

table-to-json + select + input #27

Closed andrescallejas closed 8 years ago

andrescallejas commented 8 years ago

I have a project of multiplex tables , which have select and input. I am using table- to- json and I take all the data and select the input data does not take me as I do to take further data I need to add an id to identify the property that is the information table .

imagen

Mottie commented 8 years ago

Try using the textExtractor option to look for an input or select and fallback to the cell text if nothing is found:

$('table').tableToJSON({
  textExtractor : function(cellIndex, $cell) {
    // get text from an input or select inside table cells;
    // if empty or non-existent, get the cell text
    return $cell.find('input, select').val() || $cell.text();
  }
});
andrescallejas commented 8 years ago

Thanks so solve it

andrescallejas commented 8 years ago
 $('#tablaServicio' + x).find('tbody tr').each(function (fila) {
        var s = {hora: '', empleada: '', tiempo: '', valor: ''};
        $(this).children('td').each(function (columna) {
            switch (columna) {
                case 0: //hora
                    s.hora = $(this).text();
                    break;
                case 1: //empleada
                    s.empleada = $(this).find('select').val();
                    break;
                case 2: //tiempo
                    s.tiempo = $(this).find('select').val();
                    break;
                case 3: //tiempo
                    s.valor = $(this).find('input').val();
                    break;
            }
        });
        obj.servicios.push(s);
    });

    $('#tablaProductos' + x).find('tbody tr').each(function (fila) {
        var p = {hora: '', producto: '', cantidad: '', valor: '', total: ''};
        $(this).children('td').each(function (columna) {
            switch (columna) {
                case 0: //hora
                    p.hora = $(this).text();
                    break;
                case 1: //producto
                    p.producto = $(this).find('select').val();
                    break;
                case 2: //cantidad
                    p.cantidad = $(this).find('input').val();
                    break;
                case 3: //valor
                    p.valor = $(this).find('input').val();
                    break;
                case 4: //total
                    p.total = $(this).find('input').val();
                    break;
            }
        });
        obj.productos.push(p);
    });
axuebin commented 8 years ago

thanks....