[Answered ]-Add row Id in Django data table

1👍

Based on my understanding, I think you are trying to give something like a S.No. to your table in the form of rowId for whatever purpose.

Something like enumerate in python might be needed to achieve this, In this case you can use forloop counters in django templating, available in multiple variants as follows
enter image description here

Just for reference, Here is how you can use this in your _columns variables for loop of js file

let _columns= [
    {% for field in list_fields %}
        { "data": '{{ field }}', "rowId": '{{forloop.counter}}' },
    {% endfor %}
]

Similarly, it can be used in your table as well.

I highly suggest you to have a look a official django templating forloop documentation.

👤Hemant

Leave a comment