django-eztables icon indicating copy to clipboard operation
django-eztables copied to clipboard

KeyError 'iColumns'

Open t-navi opened this issue 10 years ago • 3 comments

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

t-navi avatar Jun 07 '14 05:06 t-navi

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.

MatMoore avatar Jul 31 '14 11:07 MatMoore

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.

Venom57 avatar Aug 24 '14 16:08 Venom57

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

matlads avatar Nov 03 '14 09:11 matlads