- changed title to There is a corner case when order_columns set to be "" for all columnes
- edited description
- marked as bug
There is a corner case when the first column order_columns set to be ""
when the first column orderable flag set to be false, and the first ajax request will sent order[0][column] = 0, which could cause the datatable error.
Comments (5)
-
reporter -
reporter - changed title to There is a corner case when the first column order_columns set to be ""
- edited description
-
reporter def ordering(self, qs): if order: order = filter(lambda s:s not in ["-", ""], order) # add this line would help return qs.order_by(*order)
-
Your solution works, but order triangle icon still shows up next to the column title in table header.
-
repo owner - changed status to invalid
If I understand this issue correctly the problem appears when in JavaScript code there is a column that is not orderable while it is still used for initial ordering, like:
var dt_table = $('.datatable').dataTable( { "language": dt_language, "order": [[ 0, "desc" ]], "lengthMenu": [[25, 50, 100, 200], [25, 50, 100, 200]], "columnDefs": [ { "orderable": false, "searchable": true, "className": "center", "targets": [ 0 ] }, { "orderable": true, "searchable": true, "className": "center", "targets": [ 1 ] } ], "searching": true, "processing": true, "serverSide": true, "stateSave": false, "ajax": USERS_LIST_JSON_URL } );
Above will cause exception if the server side code doesn't define first column name in order_columns:
class UsersList110Json(BaseDatatableView): model = User columns = ['username', 'email'] order_columns = ['', 'email']
Such configuration of datatables doesn't make sense to me. If column is not orderable then it should not be set as default one. Also, even if there is a use case for this then server side code seems to be supposed to sort on that column, so there should be a definition for the first orderable column like:
order_columns = ['username', 'email']
- Log in to comment