Deferrender not working

Deferrender not working

impurfectimpurfect Posts: 4Questions: 2Answers: 0

Below is how I initialize the table. The table renders correctly with a hyperlink to the document but it loads a bit slow. I have around 4000 records and it takes around 3 secs. I want to add other columns to the table which I need to customize by render function as the below one. When I do that the render time increases to about 10 secsn which is not acceptable

I have a listener on rowCreated but it does not log anything. What am I doing wrong?

$('#listDocuments').DataTable({
"ajax" : {
'url' :'/WAS/admin/getDocumentsList',
'type' : 'GET',
'dataSrc':''
},
"destroy" : true,
"deferRender": true,
"autoWidth" : false,

    "columns": [
        {   
            'data': 'documentName',
            'defaultContent': 'documentName',
            'render': function (data, type, row, meta) {
                return generateHyperLink(row.documentName, row.documentLink);
            }
        }]

});

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,213Questions: 26Answers: 4,929

    I have a listener on rowCreated but it does not log anything. What am I doing wrong?

    I'm not sure about this. Maybe you can show the code or a test case:
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    The render function will have multiple passes for different "types". Please see the following docs for more info:
    Orthogonal Data
    columns.render

    I think you will just want to render the generateHyperLink for the display type. This way that function is only called when the row is displayed. The "Show ellipsis..." example in the columns.render doc shows an example of this.

    Kevin

  • impurfectimpurfect Posts: 4Questions: 2Answers: 0
    edited March 2018

    I added
    "createdRow": function ( row, data, index ) {
    console.log("createdRow called");
    },
    and it is called 10 times the first page is rendered as it expected.

    But still the page takes a lot of time to load. I have timed my server call and returns in about 2 secs. If I add render for just one column, it takes about 3 secs. As I add more columns and their render functions the table load time increases to about 10-14 secs.

    I have 7 columns in this table.

  • kthorngrenkthorngren Posts: 21,213Questions: 26Answers: 4,929
    Answer ✓

    My suggestion was to do something like this:

    "columns": [
        {  
            'data': 'documentName',
            'defaultContent': 'documentName',
            'render': function (data, type, row, meta) {
                console.log('render type', type);   //use this to see how the render function works
                if (type === 'display') {
                  return generateHyperLink(row.documentName, row.documentLink);
                }
              return;
            }
        }]
    

    With deferRender this should decrease the table load time.

    As a test you can see how long the table takes to load without columns.render to compare when you add the renders.

    Kevin

  • impurfectimpurfect Posts: 4Questions: 2Answers: 0

    Thank you so much. That works :)

This discussion has been closed.