data tables index erorr , list index out of range

Issue #17 invalid
Rajdeep sharma created an issue

Alert message Screenshot from 2015-11-21 11-59-50.png Get request that caused the alert Screenshot from 2015-11-21 12-00-35.png

backend

class OrderListJson(BaseDatatableView):
    # The model we're going to show
    model = matriaspirant
    columns = ['profilepic.url', 'name', 'gender', 'caste', 'dob', 'qualification', 'father_nativeplace_district',
               'address_district', 'id']
    max_display_length = 500

    def prepare_results(self, qs):
        # prepare list with output column data
        # queryset is already paginated here
        json_data = []
        for item in qs:
            json_data.append([
                item.profilepic.url if item.profilepic else "",
                item.name,
                item.gender,
                item.caste,
                item.dob.strftime("%d-%m-%Y"),
                item.qualification,
                item.father_nativeplace_district,
                item.address_district,
                item.id
            ])
        return json_data

    def get_initial_queryset(self):
        if not self.request.user.is_superuser:
                # return self.request.user.matriaspirant_set.all()
            return self.request.user.matriaspirant_set.filter(matriaspirant_status="F")
        # return self.model.objects.all()
        return self.model.objects.filter(matriaspirant_status="F")

    def filter_queryset(self, qs):
            # use parameters passed in GET request to filter queryset

            # simple example:
        search = self.request.GET.get(u'search[value]', None)
        if search:
            qs = qs.filter(name__istartswith=search)
        return qs

Cliend side

 var profiletable = $('#mytable').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": "{%  url 'order_list_json' %}",
        "columnDefs": [
            {
                // The `data` parameter refers to the data for the cell (defined by the
                // `data` option, which defaults to the column being worked with, in
                // this case `data: 0`.
                "render": function ( data, type, row ) {
                    if (Boolean(data)){  return '<a href="'+data+'"  data-lightbox="profilepic" ><img src="'+data+'" class="img-thumbnail img-responsive" style="width:60px;height:75px;" /></a>' ;}
                     return "N/A" ;
                },
                "targets": 0 // column index 
             },
             {
                // The `data` parameter refers to the data for the cell (defined by the
                // `data` option, which defaults to the column being worked with, in
                // this case `data: 0`.
                "render": function ( data, type, row ) {
                    return '<div  class="btn-group"><a  title="Edit" href="/matriaspirant/edit/'+data+'" target="_blank"  class="btn btn-primary col-xs-6"><span class="glyphicon glyphicon-edit" ></span></a><a s title="View" href="/matriaspirant/view/'+data+'" target="_blank" class="btn btn-success col-xs-6"><span class="glyphicon glyphicon-eye-open" ></span></a></div><div class="btn-group"><a   title="Move to Married" href="/move/married/'+data+'"  class="married btn btn-warning col-xs-6"><span class="glyphicon glyphicon-ban-circle" ></span></a><a  title="Move to Recycle-bin" href="/move/bin/'+data+'" class="fresh_to_bin btn btn-danger col-xs-6"><span class="glyphicon glyphicon-trash" ></span></a></div>';
                },
                "targets": 8 // column index 
             }


        ]
    } );

Comments (4)

  1. Log in to comment