Why is not detecting data of the row?

Why is not detecting data of the row?

giulichajarigiulichajari Posts: 19Questions: 8Answers: 0
edited June 2019 in Free community support

I'm creating a datatable with Editor button to redirect to other form with all fields to be edited obviously:

var t;
$(document).ready(function() {
  $.ajax({

    type: "POST",
    url: "../gestionn/views/modules/proveedor/listap.php",
    data: {
      "accion": "listar"
    },
    dataType: "json",
    error: function() {
      alert("error petición ajax");
    },
    success: function(data) {
      t = $('#prov').DataTable({

        data: data,

        columns: [{
            title: "NOMBRE",
            data: "nombre"
          },
          {
            title: "CUIT",
            data: "CUIT"
          },
          {
            title: "DEUDA",
            data: "deuda",
            render: $.fn.dataTable.render.number(',', '.', 2, '$')
          },
          {
            title: "DOMICILIO",
            data: "domicilio"
          },
          {
            title: "FIJO",
            data: "telefono"
          },
          {
            title: "CELULAR",
            data: "celular"
          },
          {
            title: "ACCION",

            className: "center",
            defaultContent: '<button type="button" class="btn btn-primary editar"><span class="fa fa-ok"></span><span
            class = "e" > EDITAR < /span></button > ',
          }
        ],
        language: {
          "sProcessing": "Procesando...",
          "sLengthMenu": "Mostrar _MENU_ registros",
          "sZeroRecords": "No se encontraron resultados",
          "sEmptyTable": "Ningún dato disponible en esta tabla",
          "sInfo": "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
          "sInfoEmpty": "Mostrando registros del 0 al 0 de un total de 0 registros",
          "sInfoFiltered": "(filtrado de un total de _MAX_ registros)",
          "sInfoPostFix": "",
          "sSearch": "Buscar:",
          "sUrl": "",

          "decimal": ",",
          "thousands": ".",
          "sLoadingRecords": "Cargando...",
          "oPaginate": {
            "sFirst": "Primero",
            "sLast": "Último",
            "sNext": "Siguiente",
            "sPrevious": "Anterior"
          },
          "oAria": {
            "sSortAscending": ": Activar para ordenar la columna de manera ascendente",
            "sSortDescending": ": Activar para ordenar la columna de manera descendente"
          }
        },


        responsive: true
      });
    }

  });


  $('#prov').on('click', '.editar', function(e) {
    var row = $(this).closest('tr');

    var data = t.row(row).data();


    var id = data.idprovedor;
    window.location.href = 'index.php?controller=proveedor&action=editar&id=' + id;
  });


});

But i get this error:
**
Uncaught TypeError: Cannot read property 'idprovedor' of undefined**

on this line:

      var id=  data.idprovedor;

Somebody can help me?

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    Hi @giulichajari ,

    Is this using Editor, or your own editing? Everything looks OK with the code, so we'd need to see it running. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • giulichajarigiulichajari Posts: 19Questions: 8Answers: 0

    Thank you again! I tried it online with those pages an i discovered i was including other JS script in the html code which doesn't correspond.

This discussion has been closed.