rrauenza
rrauenza

Reputation: 6993

Datatables deferRender not deferring

I don't understand what is wrong with this implementation. Do note that my data is "empty-ish" as I plan on created cells based on their row/col coordinates. So I pass in a dummy array and return the content in the render() callback.

You will notice in the console log it calls createdCell() 100*100 times... The html generated also agrees.

var size = 100
var zeroes = new Uint8Array(size)
var data = _.range(size).map(function() {
  return zeroes
})
var cells = 0
var rows = 0
var config = {
  autoWidth: false,
  paging: false, // Disable Paging                                   
  ordering: true, // Sortable columns                                 
  info: false, // Disable 'showing x of x entries'                 
  data: data,
  deferRender: true,
  processing: true,
  createdRow: function(cell, data, dataIndex) {
    rows += 1
  },
  columnDefs: [{
    targets: _.range(size),
    title: 'Title',
    render: function(data, type, row, meta) {
      return meta.col * meta.row
    },
    createdCell: function(cell, cellData, rowData, rowIndex, colIndex) {
      cells += 1
    },
  }],
}
var dataTable = $('#dashboard-table').DataTable(config)
console.log("Rows: " + rows)
console.log("Cells: " + cells)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>

<link href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.12/css/jquery.dataTables.min.css" rel="stylesheet"/>

<table className="table table-compressed" id="dashboard-table">
</table>

Here's the fiddle as well:

https://jsfiddle.net/rrauenza/x5nj7qgt/

Why isn't this deferring the cell creation?

Upvotes: 0

Views: 3844

Answers (1)

rrauenza
rrauenza

Reputation: 6993

Ah, I think I see what is going on. deferRender only works when paging=true in the config and defers the additional page renders.

The Datatables Scroller plugin may be closer to what I expect.

Upvotes: 2

Related Questions