It's easy to handle this core changes of views. One thing we have to sure that Views Advanced feature "Use AJAX:" should be yes.
"Use AJAX: Yes"
After that we can check our views/ajax request by Inspect and Check with Network Tab. We are giving an example to easy to use this.
Example: Suppose we have to start any view/ajax request on click on any "id" in html then our code in jquery file will be:
jQuery(document).on("click", "#prodresources", function (e) {
var arr = base_fullurl.split('/');
var page_nid = arr[2];
Drupal.attachBehaviors();
getInfo('application_resources',['block_3','block_13'], page_nid); // we are creating a function on click on "prodresources" id.
});
Parameters:
view_name : "application_resources" // that is view machine name
view_display_id : ['block_3','block_13'] // we can use multiple views block on same view.
view_args: page_nid // this is argument for view
We just have to pass these three parameters view_name:machine name and view_display_id: blocks in array in multiple case and last one is view_args: if arguments pass.
function getInfo(view_name, blocks, args) {
var base_url = window.location.origin;
$.ajax({
url: base_url+'/views/ajax',
type: 'post',
data: {
view_name: view_name,
view_display_id: blocks,
view_args: args,
},
dataTypeview_display_id: 'json',
success: function (response) {
if (response[3] !== undefined) {
var viewHtml = response[3].data;
$('#destination_id').html(viewHtml);
Drupal.attachBehaviors();
}
},
error: function(data) {
alert('An error occured!');
}
});
}
Note: How to apply changes on views ajax according to requirement in Drupal 8?
"Use AJAX: Yes"
After that we can check our views/ajax request by Inspect and Check with Network Tab. We are giving an example to easy to use this.
Example: Suppose we have to start any view/ajax request on click on any "id" in html then our code in jquery file will be:
jQuery(document).on("click", "#prodresources", function (e) {
var arr = base_fullurl.split('/');
var page_nid = arr[2];
Drupal.attachBehaviors();
getInfo('application_resources',['block_3','block_13'], page_nid); // we are creating a function on click on "prodresources" id.
});
Parameters:
view_name : "application_resources" // that is view machine name
view_display_id : ['block_3','block_13'] // we can use multiple views block on same view.
view_args: page_nid // this is argument for view
We just have to pass these three parameters view_name:machine name and view_display_id: blocks in array in multiple case and last one is view_args: if arguments pass.
function getInfo(view_name, blocks, args) {
var base_url = window.location.origin;
$.ajax({
url: base_url+'/views/ajax',
type: 'post',
data: {
view_name: view_name,
view_display_id: blocks,
view_args: args,
},
dataTypeview_display_id: 'json',
success: function (response) {
if (response[3] !== undefined) {
var viewHtml = response[3].data;
$('#destination_id').html(viewHtml);
Drupal.attachBehaviors();
}
},
error: function(data) {
alert('An error occured!');
}
});
}
Note: How to apply changes on views ajax according to requirement in Drupal 8?
No comments:
Post a Comment