1

Lo que ocurre es que hago un CRUD con mostrando con datatable, cada vez que agrego un nuevo campo, agrega, pero sin embargo el tr que se ha agregado no tiene id la cual necesito para poder eliminar la fila tr

Eliminar

tabla.row($("tr[id=" + id + "]")).remove().draw(false);

Agregar

         var row=tabla.row.add([
            msg.lines_product.description,
            msg.description,
            msg.abreviation,
            function (data, type, row, meta) {
                if (msg.status === 0) { return '<span class="label label-danger">In Activo</span>' }
                if (msg.status === 1) { return '<span class="label label-success">Activo</span>' }
                if (msg.status === 2) { return '<span class="label label-warning">Bloqueado</span>' }
            },
            function (data, type, row, meta) {
                return '<a class="btn btn-warning" onclick="bsl(' + msg.id + ')" href="#"><i class="fa fa-edit"></i></a><a href = "#" onclick = "remove(' + msg.id +')" class="btn btn-danger"> <i class="fa fa-trash"></i></a>';
            }
        ]).draw();

utilizé $(row).attr('id', msg.id); pero no agrega nada, las tablas estan distribuidas con td

necesito saver como agrego id a la nueva fila que se va a agregar o eliminar tr via parent al hacer click en un boton

1 respuesta 1

1

Te sirve: https://datatables.net/reference/option/createdRow

"createdRow": function( row, data, dataIndex ) {
  $(row).attr(id', 'algun valor' );
}

Es un atributo más de la definición de la datatable. Aquí data es la información que pasaste a tabla.row.add([]). Solo que estas limitado a la info que pasaste como parámetro. Igual te sirve

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.