Pagination With Horizon And Multiple Tables In The Same View

I was making a custom dashboard for Horizon the other day. In one of my views I was using tabs and in each tab I had a table that supported pagination. There was a problem where when I would go to tab 2 page 2 I would get an error about not being able to load data for tab 1. It was pretty clear to me this was an issue with pagination. I tried various things to work around the bug I had but nothing seemed to work. I took the advice a good friend of mine always gives me when I get stuck “Dont trust the docs, they lie. Go read the code its the only source of truth.” so I did just that. I quickly found the answer to my problem. Inside the tables base class I found the class had a variable for pagination that defaulted to “marker” and in the comments for that particular variable it said “When using multiple tables in a single view this will need to be changed to differentiate between the tables.”. That was simple enough, like always I wish I had gone to read the code sooner. Now to implement the fix and get rid of my bug all I had to do was go to my table classes and add the following bits of code:

class ImageTable(tables.DataTable):
    name = tables.Column("name", verbose_name=_("Name"),
                         link="horizon:admin:images:detail")
    properties = tables.Column(images_md_to_str, verbose_name=_("Metadata"))

    class Meta(object):
        name = "images"
        verbose_name = _("Images")
        table_actions = (MetadataFilterAction, CreateImage, DeleteImage, )
        launch_actions = ()
        if getattr(settings, 'LAUNCH_INSTANCE_LEGACY_ENABLED', False):
            launch_actions = (LaunchImage,) + launch_actions
        if getattr(settings, 'LAUNCH_INSTANCE_NG_ENABLED', True):
            launch_actions = (LaunchImageNG,) + launch_actions
        row_actions = launch_actions + (CreateVolumeFromImage,
                                        EditImage, UpdateMetadataImg,
                                        DeleteImage,)
        # Define the following 2 variables to fix pagination issues
        pagination_param = 'image_marker'
        prev_pagination_param = 'prev_image_marker'

Defining the pagination_param & prev_pagination_param and using a unique name for each class is all it takes to fix that issue. I hope this info comes in handy for someone out there. I spent more time on trying to fix this than Id care to admit 😉

Happy Stacking!