I am currently rendering a view manually like so:
$content = \Drupal::service('renderer')->renderPlain(views_embed_view('user_admin_people', 'page_1'));
Then I'm sending the html to the page and inserting it into a div with javascript. I needed to use renderPlain()
rather than render()
because when I was doing that, I was getting this error:
LogicException: Render context is empty, because render() was called outside of a renderRoot() or renderPlain() call. Use renderPlain()/renderRoot() or #lazy_builder/#pre_render instead.
Now, you're probably thinking, why don't you just use render arrays normally and let Drupal handle it? Unfortunately, I can't do that, I need to render the view's html and send it to the page, which I have already done. BUT, when I do this, clicking on 'Filter' brings me to the /admin/people page of the Drupal site (on which it will do ajax filters properly, because it rendered from a normal render array).
How could I attach the javascript to this view html so that it reloads its data via ajax instead of linking me to the view's page? I have already tried Drupal.attachBehaviors(), thinking that it would run something from ajax_view.js from views (which is a confusing & large file).
Or, where would I look in core to find out more about this, or where is some good documentation to read? Am I looking in the right place in core, looking at ajax_views.js?