Girdfield pagination on v4.x

<%- if @topic_view.topic.tags.present? %>
<%= t 'js.tagging.tags' %>: <%- @topic_view.topic.tags.each do |t| %> <%= t %> <%- end %>
<% end %>

Silverstripe Version 4.4.4

Question:

I’m having trouble setting the number of items per page on a Gridfield list in v4

Previously (v3) I would have done it like this:

$gridFieldConfig->getComponentByType('GridFieldPaginator')->setItemsPerPage(50);

I’ve added these two namespaces

    use SilverStripe\Forms\GridField\GridFieldConfig;
    use SilverStripe\Forms\GridField\GridFieldPaginator;

but I get “Uncaught Error: Call to a member function setItemsPerPage() on null

Can anyone point me in the right direction to get this working?

Instead of “GridFieldPaginator” try GridFieldPaginator::class?

Alternatively, if you want to set this globally, try adding the following YML:

SilverStripe\Forms\GridField\GridFieldPaginator:
  default_items_per_page: 20