noirbizarre / django-eztables

Easy integration between jQuery DataTables and Django.
http://django-eztables.readthedocs.org/en/latest/
GNU Lesser General Public License v3.0
96 stars 36 forks source link

KeyError 'iColumns' #25

Open t-navi opened 10 years ago

t-navi commented 10 years ago

Hi. When I trying to look what kind of json will be

view.py

class TempDatatablesView(DatatablesView):
    model = Deal
    fields = (
         'deal_name',
    )

url.py

 url(r'^test/$', TempDatatablesView.as_view(), name='deals_list_json'),

I catch exeption:

in eztables/forms.py in init, line 22

for idx in xrange(int(self.data['iColumns'])): 

Python Version: 2.7.6 Django Version: 1.6.5

MatMoore commented 10 years ago

This problem is caused by the API changing in Datatables.net 1.10.

To fix it we need to parse the parameters defined here: https://datatables.net/manual/server-side

This is slightly annoying as it doesn't send through the number of columns/order columns anymore, and django doesn't parse the arrays; I get separate values for columns[0][data] columns[1][data] etc.

The problem seems to be localised to DatatablesForm - if I modify the request data on the way in the generated output appears to work fine with the new datatables.

@noirbizarre do you have any thoughts on this? I'm not really sure what the cleanest way to handle both new/old versions would be.

There is a workaround described at https://datatables.net/manual/server-side#Legacy - passing through sAjaxSource instead of ajax on the javascript side.

Venom57 commented 10 years ago

I'm experiencing this same issue with just the DatatablesView as the OP was.

I've tried to use the Legacy support mode as suggested by @MatMoore but I'm still receiving the KeyError. It looks like it's happening between the url and view code, i.e. commenting out all table generation in my template still throws the same error.

matlads commented 10 years ago

Any update on this issue? I am currently running into this same exact issue. Did any workaround get created?