There is a corner case when the first column order_columns set to be ""

Issue #9 invalid
Ryan Fan created an issue

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)

  1. Ryan Fan 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)
    
  2. Erik Telepovský

    Your solution works, but order triangle icon still shows up next to the column title in table header.

  3. Maciej Wisniowski repo owner

    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']
    
  4. Log in to comment