-
-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FieldError when sorting a column which defines a function as the 'data' attribute #86
Comments
I've reproduced the issue here. To reproduce:
|
I am getting the error when search is done. custom functions are not working. |
hey @matthewhegarty take a look at #83 . set orderable: false, searchable: false, |
This should be documented, as well as other cases where setting |
@izimobil why don't you want to use $('#player-table').DataTable({
"serverSide": true,
"ajax": {
"url": "{% url "api:player-list" %}?format=datatables",
},
"columns": [
"data": function ( row, type, val, meta ) {
return row.my_val;
},
"name": "my_val"
]
}) Just modify that lines django-rest-framework-datatables/rest_framework_datatables/filters.py Lines 54 to 65 in fab94a9
like this col = 'columns[%d][%s]'
data = get_param(request, col % (i, 'data'))
name = get_param(request, col % (i, 'name'))
if (data == 'function') and name:
data = name (not a full replacement, just for illustration). |
My Javascript defines a function for the
columns.data
attribute:This works fine when displaying the table - the values are rendered correctly. However, when sorting the column, this sends a request which triggers a crash with
FieldError
:Exception Type: FieldError at /api/player/ Exception Value: Cannot resolve keyword 'function' into field.
Sure enough, the request sends
data=function
, and I thought that this was the source of the issue, but this actually gets sent with successful requests as well.Crashes:
Returns OK:
Stack trace:
drfdt_st1.txt
Workaround
Very very nasty hack is to declare an attribute on the model in question called
function
. This prevents the crash, but sorting still does not work.The text was updated successfully, but these errors were encountered: