Код: Выделить всё
def my_page_view(request):
columns = generate_datatables_columns("MyModel")
return render(
request,
"my_page.html",
{"columns": columns}
)
Код: Выделить всё
$(document).ready(function() {
var columns = [];
{% for col in columns %}
var jsObject = {
{% for key, value in col.items %}
"{{ key }}": "{{ value }}",
{% endfor %}
};
columns.push(jsObject);
{% endfor %}
var table = $('#my-table').DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "/my/url",
"type": "GET",
},
"columns": columns,
});
});
{% for column in columns %}
{{ column.name }}
{% endfor %}
Код: Выделить всё
var table = $('#my-table').DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "/my/url",
"type": "GET",
"dataSrc": function (json) {
var data = json.data;
var newColumns = columns;
// make changes on data and newColumns variables with some conditions...
// here should update the datatable columns with the value of newColumns.
return data;
}
},
"columns": columns,
});
Буду очень благодарен, если кто-нибудь мне в этом поможет.
Подробнее здесь: https://stackoverflow.com/questions/788 ... rom-server