bradleyayers/django-tables2 — pull request #172 by mesuutt (2013-12-01 15:35:24+00:00)
Title: Working with emulated list sequence

Hi,

I am fetching table data from API and giving it as data to Table but I am fetching a few items from API not all. Data was converting to list in `tables.py` and length of the data using as page count so pagination not working correct. I fixed this bug.

Simple code:

`````python

class MyTableData(list):
def __init__(self, data):
self.data = data

def __iter__(self):
for item in self.data['objects']:
yield item

def __len__(self):
return self.data['meta']['total_count']

def __getitem__(self, position):
return self.data['objects'][position]

def sort(self, **kwargs):
self.data['objects'].sort(**kwargs)

data = { 'meta':{ 'total_count': 3, 'offset': 0, 'limit': 1}
'objects': [
{'name': 'Foo', 'id': 1},
{'name': 'Bar', 'id': 2},
{'name': 'Baz', 'id': 3}
]}

table_data = MyTableData(data)
table = MyTable(table_data)
table.paginate(page=self.request.GET.get('page', 1), per_page=1)

`````

> I know little English. I hope you understand me.