morlandi / django-ajax-datatable

A Django app which provides the integration of a Django project with the jQuery Javascript library DataTables.net
MIT License
204 stars 64 forks source link

Display a key-value model in datatables #115

Open fbzyx opened 1 year ago

fbzyx commented 1 year ago

First of all thank you for the great project :)

I have a model where i store a key and a value like this:

class DataModel(models.Model):
    key = models.CharField(max_length=128)
    value = models.CharField(max_length=128)

The value in key is the name that i want to use as header or column name (in column defs) and the field value is the field that i want to display in the table.

So the table should look like this:

|key1|key2|key3|key4| |value1|value2|value3|value4| |value1|value2|value3|value4| . . . . . . . .

How could i implement something like this? where should i start? Is there an example i can see?

In all the examples and implementations I have done before I always have to put the field name in column_defs. What I want now is to do it dynamically, since I don't know what value the field "key" will have..