Closed doganmeh closed 8 years ago
I have an updated fix on my working branch, which has 2 / 3 of the original pr.
1 part which I called magic, got fixed by the updates you pushed. but I still don't understand how is the config
introduced in Datatable.init(), and am curiuos :) there is no reference to it in the meta class either.
I am not sure if this is the question but the settings get pulled via ajax by the javascript file https://github.com/pivotal-energy-solutions/django-datatable-view/blob/master/datatableview/static/js/datatableview.js
I am somewhat sure settings are put in table headers <th>
attributes, and deciphered from there on the client side by javascript. So, no ajax should be going back to the server for that. The only ajax that goes is for the table data in json.
I'm fairly certain this is the issue from #113 . In datatables.js 1.10.x, they use a jQuery.data()
call to store a 'sorting' value, and it shadows the setting I'm putting there. I think it might be as simple as changing the data attribute name we use, but I'll have to set up to test that before I commit a change.
'data attribute name' ? do you mean ordering
? that is how we set up ordering in the Datatable class. e.g,
class MyDatatable(Datatable):
class Meta:
model = Entry
columns = ['id', 'headline', 'pub_date', 'n_comments', 'n_pingbacks']
ordering = ['-id'] ############ THIS ONE !!! #############
page_length = 5
search_fields = ['blog__name']
unsortable_columns = ['n_comments']
hidden_columns = ['n_pingbacks']
structure_template = 'datatableview/default_structure.html'
class ConfigureDatatableObjectDatatableView(DatatableView):
model = Entry
datatable_class = MyDatatable
Actually, it appears my memory failed me, as I patched the attribute names last year without referencing the ticket: b170816
This might yet be something else.
Here are the two requests go to the server when I run http://127.0.0.1:8081/configure-datatable-object/:
[05/Oct/2016 21:29:26] "GET /configure-datatable-object/ HTTP/1.1" 200 16338
[05/Oct/2016 21:29:26] "GET /configure-datatable-object/?draw=1&columns%5B0%5D%5Bdata%5D=0&columns%5B0%5D%5Bname%5D=id&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=1&columns%5B1%5D%5Bname%5D=headline&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=true&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=2&columns%5B2%5D%5Bname%5D=pub-date&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=true&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B3%5D%5Bdata%5D=3&columns%5B3%5D%5Bname%5D=n-comments&columns%5B3%5D%5Bsearchable%5D=true&columns%5B3%5D%5Borderable%5D=false&columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B4%5D%5Bdata%5D=4&columns%5B4%5D%5Bname%5D=n-pingbacks&columns%5B4%5D%5Bsearchable%5D=true&columns%5B4%5D%5Borderable%5D=true&columns%5B4%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B4%5D%5Bsearch%5D%5Bregex%5D=false&start=0&length=5&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1475702966822 HTTP/1.1" 200 1130
>>> urllib.parse.parse_qs('...')
{'columns[0][name]': ['id'],
'columns[4][orderable]': ['true'],
'columns[2][orderable]': ['true'],
'columns[3][name]': ['n-comments'],
'columns[4][data]': ['4'],
'columns[1][name]': ['headline'],
'columns[1][searchable]': ['true'],
'columns[0][orderable]': ['true'],
'columns[2][searchable]': ['true'],
'columns[2][data]': ['2'],
'columns[0][search][regex]': ['false'],
'columns[2][name]': ['pub-date'],
'columns[4][searchable]': ['true'],
'columns[1][search][regex]': ['false'],
'length': ['5'],
'_': ['1475702966822'],
'/configure-datatable-object/?draw': ['1'],
'columns[4][name]': ['n-pingbacks'],
'columns[0][data]': ['0'],
'search[regex]': ['false'],
'columns[3][searchable]': ['true'],
'columns[3][data]': ['3'],
'columns[4][search][regex]': ['false'],
'columns[1][data]': ['1'],
'columns[0][searchable]': ['true'],
'columns[3][search][regex]': ['false'],
'columns[3][orderable]': ['false'],
'columns[2][search][regex]': ['false'],
'start': ['0'],
'columns[1][orderable]': ['true']}
So bottom line: it is indeed something else, there is nothing here related to sorting.
See #152
This issue also recurred, see #145. Also see '/configure-datatable-object/' example view.