Dejell Dejell - 5 months ago 31
Python Question

django-datatable default iDisplayLength

I am using https://github.com/shymonk/django-datatable for a table.

By default, it would display only 10 records, and there is a Length Menu to choose a different number.

I see in the Ajax call that it asks for

iDisplayLength=10
on first load.

How can I overwrite it to display 100 at first?

I read through the source code and the documentation, but I am newbie to django and not sure how to overwrite it

Answer

I can see from their source code: class TableOptions which is used for meta options and can be accessed for the same to set different properties.

So as I see it, adding a Meta can help you, like this:

class AjaxTable(Table):
    id = Column(field='id', header=u'#')
    name = Column(field='name', header=u'NAME')
    organization = Column(field='organization.name', header=u'ORG')

    class Meta:
        model = Person
        ajax = True
        page_length = 100  # Add this and see

The page_length is the set of options that I could see inside the TableOptions

Comments