drawcallback inside column data

drawcallback inside column data

Coder102Coder102 Posts: 78Questions: 2Answers: 0
drawCallback: function (hola) {
    hola= $('#average').DataTable().column(0).data().sum() /$('#average').DataTable().rows().count();
    $('#totaal').html(hola);
  },
  columns: [ 
    {
      title:
        "Tiempo promedio",
      data: "",
      render: function (data, type, row) {
        return (
          data
        );
      },
    }, 
  ],

>
Hello, I want to put the result that the drawcallback gives me (it is a number) inside the column "Tiempo promedio" and show it to me in the table. It can?

Replies

  • kthorngrenkthorngren Posts: 20,268Questions: 26Answers: 4,765

    The drawCallback option runs after columns.render. Also columns.render doesn't always run when the table is drawn. It only runs if its needed like for table data changes.

    Are you saying that you want one column to display the total hola in each row of the table?

    You can use cells().every() in drawCallback to iterate a column to update the data in that column. Something like this:

    drawCallback: function (hola) {
        hola= $('#average').DataTable().column(0).data().sum() /$('#average').DataTable().rows().count();
        $('#totaal').html(hola);
        this.api().cells(null, 1).every( function () {
            this.data( hola );
        } );
      },
    

    Where cell(null, 1) means all rows and column 1.

    Kevin

This discussion has been closed.