reinitialize fila example eliminar delete bootstrap jquery sorting datatables rows delete-row

example - Cómo eliminar la fila actual con el plugin jquery datatable



jquery datatable get selected row (5)

Tengo una columna con botones en una tabla. Estoy usando el plugin jQuery datatable. Los botones dicen "Eliminar" y la idea es que al hacer clic en ese botón, borre la fila actual en la tabla.

Cuando llamo a fnDeleteRow parece funcionar la primera vez, pero no hay más tiempo para esa fila, así que parece que en realidad no está borrando la fila correctamente.


Así es como funciona para mí. En la función de documento listo, asigno la versión convertida de la tabla HTML a una variable y cuando se hace clic en un botón voy por padres / hijos con JQuery y envío la fila que obtengo como parámetro a la función fnDeleteRow () de la biblioteca.

Aquí están los comentarios de la función de la biblioteca. Y un ejemplo que se menciona en la biblioteca.

/** * Remove a row for the table * @param {mixed} target The index of the row from aoData to be deleted, or * the TR element you want to delete * @param {function|null} [callBack] Callback function * @param {bool} [redraw=true] Redraw the table or not * @returns {array} The row that was deleted * @dtopt API * @deprecated Since v1.10 * * @example * $(document).ready(function() { * var oTable = $(''#example'').dataTable(); * * // Immediately remove the first row * oTable.fnDeleteRow( 0 ); * } ); */ // And here''s how it worked for me. var oTable; $("document").ready(function () { oTable = $("#myTable").dataTable(); }); //Remove/Delete button''s click. $("a[name=''deleteColumn'']").click(function () { var $row = $(this).parent().parent(); oTable.fnDeleteRow($row); });


Digamos que adjuntó una función para llamar cuando el usuario hace clic en el botón. La función sería algo como esto

function DeleteRow(event) { //get the row of the cell that is clicked var $row = $(this).parents("tr").eq(0) //if you need the id you can get it as var rowid = $row.attr("id"); //now you can call delete function on this row $row.delete(); }


Prueba esto:

var row = $(this).closest("tr").get(0); oTable.fnDeleteRow(oTable.fnGetPosition(row));

Si no funciona, verifique el siguiente example


Qué tal esto:

// Delete Row $(''.glyphicon-minus'').on("click", function() { configTable.row($(this).closest("tr").get(0)).remove().draw(); });


de esta página :

$(''#example tbody td'').click( function () { /* Get the position of the current data from the node */ var aPos = oTable.fnGetPosition( this ); //... } );