I'm trying to refresh my View in Drupal 8 without reloading the page with this code :
(function ($, Drupal) {
'use strict';
setInterval(function() {
$('.view-message-activity-stream-timeline-public').trigger('RefreshView');
}, 10000);
})(jQuery, Drupal);
My module :
<?php
/**
* @file
* Holds hook implementation for the Message Activity Stream module.
*/
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\group\Entity\Group;
use Drupal\node\Entity\Node;
use Drupal\comment\Entity\Comment;
use Drupal\commerce_store\Entity\Store;
use Drupal\commerce_product\Entity\Product;
use Drupal\user\Entity\User;
use Drupal\message\Entity\Message;
/**
* Implements hook_ajax_render_alter().
*/
function message_activity_stream_ajax_render_alter(array &$data) {
foreach ($data as $key => $command) {
if ($command['command'] === 'viewsScrollTop') {
unset($data[$key]);
break;
}
}
}
/**
* Implements hook_user_insert().
*/
function message_activity_stream_user_insert(User $account) {
$message = Message::create(['template' => 'mas_user_register', 'uid' => $account->id()]);
$message->set('field_user_reference', $account);
$message->save();
}
/**
* Implements hook_commerce_store_insert().
*/
function message_activity_stream_commerce_store_insert(Store $commerce_store) {
$message = Message::create(['template' => 'mas_create_store', 'uid' => $commerce_store->get('uid')]);
$message->set('field_store_reference', $commerce_store);
$message->save();
}
/**
* Implements hook_commerce_product_insert().
*/
function message_activity_stream_commerce_product_insert(Product $commerce_product) {
$message = Message::create(['template' => 'mas_create_product', 'uid' => $commerce_product->get('uid')]);
$message->set('field_product_reference', $commerce_product);
$message->save();
}
/**
* Implements hook_group_insert().
*/
function message_activity_stream_group_insert(Group $group) {
$message = Message::create(['template' => 'mas_create_group', 'uid' => $group->get('uid')]);
$message->set('field_group_reference', $group);
$message->save();
}
/**
* Implements hook_node_insert().
*/
function message_activity_stream_node_insert(Node $node) {
$message = Message::create(['template' => 'mas_create_node', 'uid' => $node->get('uid')]);
$message->set('field_node_reference', $node);
$message->save();
}
/**
* Implements hook_comment_insert().
*/
function message_activity_stream_comment_insert(Comment $comment) {
$message = Message::create(['template' => 'mas_create_comment', 'uid' => $comment->getOwnerId()]);
$message->set('field_comment_reference', $comment);
$message->save();
}
It works.
My problem :
At the bottom of my page I have a pagination button "Afficher plus" (the button that is the full width of the page). When the page refreshes automatically (every 10 seconds), it returns to the first page.
https://www.s1biose.com/fr