jQuery DataTables default column value (with JSFiddle example)

jQuery DataTables default column value (with JSFiddle example)

webuserwebuser Posts: 2Questions: 1Answers: 0

I am trying to include an invisible column in a jQuery DataTable that can be set to default value true in place of a null or undefined encountered in the underlying data source. The JSFiddle is here. If you click on the Select button in the first two rows (populated from data), it yields undefined. The Select button on the third row (added dynamically) yields false. I want the first two rows' Select button to yield true.

Say I am working with a 6-columns DataTable. The first 5 columns are visible. The 6th column is set to not be visible. And it must contain either a true or false, and a default value of true. I tried this but it did not work.

{ "defaultContent": true, "data": "existing", "visible": false }

According to the API, I think defaultContent works only when data is null; maybe that's why I can't get it to work. How do I do this?

Answers

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    The row().data() method gives you the original data object for the row, which is why there is no value for existing - since it doesn't exist in the original data.

    If you need to set a value in the object, then you would need to do that. defaultContent is used in place of content - it does not write to the original object.

    Allan

  • webuserwebuser Posts: 2Questions: 1Answers: 0

    Is there a way to access the defaultContent value on the selected row?

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    After initialisation, the only way to be able to access it would be if it were used in the cel, and you read it from the cell's DOM element. There isn't a public API to be able to get the defaultContent for a column after initialisation (although you could store it in a local variable yourself and access it that way if you need it).

    Allan

This discussion has been closed.