Is it possible to make column.defaultContent to load itself into the data field?

Is it possible to make column.defaultContent to load itself into the data field?

minifiredragonminifiredragon Posts: 82Questions: 16Answers: 2

As per the answer to https://datatables.net/forums/discussion/41038/about-defaultcontent-and-render-options,

Is it possible to store that information into the actual data field so the column.render function does not need additional branching code to handle undefined/null data?

Also can the manual for column.defaultContent be updated to make it clear that using it does not affect the column.render function and additional coding should be added to handle undefined/null values. The way it is currently worded leads one to believe it would be used by the column.render.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,599Questions: 1Answers: 10,486 Site admin

    Hi,

    Could you illustrate what you are trying to do for me please? In the thread you linked to, if date_at was null, then that is what data would be in the rendering function, and you'd probably need an if statement to handle that.

    Regarding columns.defaultContent - if the rendering function returns null, the default content would be used: https://live.datatables.net/dodobuge/58/edit .

    It should be noted that an HTML sourced table is slightly different since it has data in the cell already, and that doesn't get overwritten: https://live.datatables.net/wahehefe/1/edit . That second one is perhaps a bug.

    Allan

  • minifiredragonminifiredragon Posts: 82Questions: 16Answers: 2

    Example: https://live.datatables.net/dodobuge/59/

    Here is what I am doing: I build a table dynamically and load it to the webpage (so we have a blank Datatable). Then I call the server for the data to populate the table, which is then loaded. In some cases, I added a new column to my table (with column.render field added sometimes if I want to format the data) that the current server data does not know about, so therefore does not provide that data bit for the table.

    When this happens, Datatabables throws the error that it cannot find such and such data. The columns.defaultContent does a good job at quenching that error, but I have to code in a branch in column.render to handle the undefined response from the table (I thought defaultContent would supply that missing bit). When the table is updated, that missing data section is added to the server data.

  • allanallan Posts: 63,599Questions: 1Answers: 10,486 Site admin

    Thank you - if I understand correctly, you are expecting the order of execution to be data -> defaultContent -> renderer - is that correct? It is actually data -> renderer -> defaultContent. The renderer can supply content to display in the table, even if there is no data. And failing the renderer supplying anything, then it will move on to default content.

    Now, that said, I'm actually quite surprised that nothing is showing up in the final column in the example there. I'm going to look into that further in the morning.

    Allan

  • kthorngrenkthorngren Posts: 21,388Questions: 26Answers: 4,961
    edited January 16 Answer ✓

    I'm actually quite surprised that nothing is showing up in the final column in the example there.

    Just need to add a little CSS to see the content of the i element.
    https://live.datatables.net/dodobuge/61/edit

    Kevin

  • minifiredragonminifiredragon Posts: 82Questions: 16Answers: 2

    @allan data -> defaultContent -> renderer Yes, that is how I would expect it. And updating the explanation for columns.defaultContent with a note that says this would help.

  • allanallan Posts: 63,599Questions: 1Answers: 10,486 Site admin

    Just need to add a little CSS

    Doh!!! Can't believe I didn't think of that! Thanks Kevin.

    I'll get the defaultContent docs updated to clarify the data order.

    Allan

  • allanallan Posts: 63,599Questions: 1Answers: 10,486 Site admin

    Statement add to clarify the order of the data sequence.

    Allan

Sign In or Register to comment.