Valid column definition formats

There are numerous ways to specify a column for a datatable, depending on what you need to accomplish. The following formats are all valid ways to write a column definition in a view's datatable_options:

datatable_options = {
    'columns': [
        # "concrete" field backed by the database
        'name',  # field's verbose_name will be used
        ("Name", 'name'),  # custom verbose name provided
        ("Name", 'name', 'callback_attr_name'),  # callback looked up on view
        ("Name", 'name', callback_handle),  # calback used directly

        # non-field, but backed by methods, properties, etc
        "Virtual Field",

        # "fake" virtual field whose data is generated by the view
        ("Virtual Field", None, 'callback_attr_name'),
        ("Virtual Field", None, callback_handle),
    ],
}
    

For concrete fields that also provide callbacks, the actual database value will be consulted during searches and sorts, but the table will use the return value of the callback as the display data.

Virtual fields are useful ways to mount methods onto a table. Consider a read-only property that generates its return value based on some underlying database field:

datatable_options = {
    'columns': [
        ("Average profit", 'get_average_profit'),
    ],
}
    

Be careful with virtual columns that might cause database queries per-row. That doesn't scale very well!