Use Datatable out Datatable function

Use Datatable out Datatable function

Coder102Coder102 Posts: 78Questions: 2Answers: 0

Hola, necito acceder a las propiedades de datatable fuera de la funcion de datatable. Tengo una funcion fuera pero si quiero instanciar otra vez el datatable dentro de mi funcion me tira un error que dice "No se puede reinstanciar el datatable con el mismo id", alguien sabe como puedo acceder a las propiedades?

let handleClick = function () { ESTA ES LA FUNCION DONDE QUIERO ACCEDER A LAS PROPIEDADES DE DT
document.getElementById("btnExpandCollapse");
$('#total').dataTable( { TIRA ERROR PORQUE NO SE PUEDE INSTANCIAR 2 VECES
"data": data,
"columns": [
{title: "Read",
data: "Inner",
visible: false,
render: function (data, type, row) {
if (type === "display") {
if (data.length > 0) {
return data[0].tiempo;
}
} else {
return data;
}
}}
]
} );

$(document).ready(function () { ESTA ES LA FUNCION ORIGINAL DE DATATABLE
var table = $("#total").DataTable({
data: data,
info: false,
dom: "Bfrtip",
buttons: {
buttons: [
{
extend: "colvis",
className: "fa fa-plus-square fa-lg mb-3",
text: " Extend details",
collectionLayout: "fixed four-column",
},
],
dom: {
button: {
tag: "button",
className: "btn btn-light mb-1 w-100 border",
},
},
},
columns: [
{
title: "Total Time",
data: "tiempo",
render: function (data, type, row) {
return (
data +
"<button onClick='handleClick()' class='btnExpandCollapse btn btn-outline-light text-dark border fa fa-plus fa-lg ml-3 '></button>"
);
},
},

Replies

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    When you initialise again, just call DataTables() without any options - that will give you an object for the existing DataTable,

    Colin

  • Coder102Coder102 Posts: 78Questions: 2Answers: 0

    Perdon, no entiendo. Yo solo quiero acceder a las propiedades del datatable (a las columnas) fuera de la funcion datatable

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736

    See answer in this thread.

    Kevin

This discussion has been closed.