Decoupled Drupal Search JSON: API

I want to filter by year clicking in a checkbox, example, each checkbox has a year assigned to the value, but need to filter them when i click in each one, i am using a paginator of 10 elements in Drupal 9 Views JSON API.

the json response will be something like this:

http://example.com/jsonapi/views/busqueda_avanzada/informes?page=0&views-filter%5Bano%5D%5B0%5D=2020&views-filter%5Bano%5D%5B1%5D=2019&views-filter%5Bano%5D%5B2%5D=2002 

that is too long, without saying that i have to use multiple for statements for that to assign the index everytime anybody click on that…

This is the HTML

<li><span><strong>Año</strong></span></li> <li>    <input type="checkbox" value="2000" class="form-check-input" [checked]="false" #ano2000 (change)="getYear(ano2000.value)">    2000    <input type="checkbox" value="2001" class="form-check-input" [checked]="false" #ano2001 (change)="getYear(ano2001.value)">    2001    <input type="checkbox" value="2002" class="form-check-input" [checked]="false" #ano2002 (change)="getYear(ano2002.value)">    2002    <input type="checkbox" value="2003" class="form-check-input" [checked]="false" #ano2003 (change)="getYear(ano2003.value)">    2003 </li> <li>    <input type="checkbox" value="2004" class="form-check-input" [checked]="false" #ano2004 (change)="getYear(ano2004.value)">    2004    <input type="checkbox" value="2005" class="form-check-input" [checked]="false" #ano2005 (change)="getYear(ano2005.value)">    2005    <input type="checkbox" value="2006" class="form-check-input" [checked]="false" #ano2006 (change)="getYear(ano2006.value)">    2006    <input type="checkbox" value="2007" class="form-check-input" [checked]="false" #ano2007 (change)="getYear(ano2007.value)">    2007 </li> <li>    <input type="checkbox" value="2008" class="form-check-input" [checked]="false" #ano2008 (change)="getYear(ano2008.value)">    2008    <input type="checkbox" value="2009" class="form-check-input" [checked]="false" #ano2009 (change)="getYear(ano2009.value)">    2009    <input type="checkbox" value="2010" class="form-check-input" [checked]="false" #ano2010 (change)="getYear(ano2010.value)">    2010    <input type="checkbox" value="2011" class="form-check-input" [checked]="false" #ano2011 (change)="getYear(ano2011.value)">    2011 </li> <li>    <input type="checkbox" value="2012" class="form-check-input" [checked]="false" #ano2012 (change)="getYear(ano2012.value)">    2012    <input type="checkbox" value="2013" class="form-check-input" [checked]="false" #ano2013 (change)="getYear(ano2013.value)">    2013    <input type="checkbox" value="2014" class="form-check-input" [checked]="false" #ano2014 (change)="getYear(ano2014.value)">    2014    <input type="checkbox" value="2015" class="form-check-input" [checked]="false" #ano2015 (change)="getYear(ano2015.value)">    2015 </li> <li>    <input type="checkbox" value="2016" class="form-check-input" [checked]="false" #ano2016 (change)="getYear(ano2016.value)">    2016    <input type="checkbox" value="2017" class="form-check-input" [checked]="false" #ano2017 (change)="getYear(ano2017.value)">    2017    <input type="checkbox" value="2018" class="form-check-input" [checked]="false" #ano2018 (change)="getYear(ano2018.value)">    2018    <input type="checkbox" value="2019" class="form-check-input" [checked]="false" #ano2019 (change)="getYear(ano2019.value)">    2019 </li> <li class="margin_24">    <input type="checkbox" value="2020" class="form-check-input" [checked]="false" #ano2020 (change)="getYear(ano2020.value)">    2020    <input type="checkbox" value="2021" class="form-check-input" [checked]="false" #ano2021 (change)="getYear(ano2021.value)">    2021 </li> <li> 

My service

 get informesNodes() {     return 'http://example.com/jsonapi/views/busqueda_avanzada/informes?page=' + this.pageNumber + '&views-filter[titulo]=' + this.titulo + '&views-filter[field_organismo_auditado_target_id]=' + this.organismoId + '&views-filter[field_tipo_de_auditoria_target_id]=' + this.auditoriaId + '&views-filter[ano]=' + this.year;   }    constructor(private http: HttpClient) { }      getNodes(): Observable<InformesCounter> {     this.pageNumber = 0;     return this.http.get<InformesCounter>(`${this.informesNodes}`);   }    getYear(year: any): Observable<Year> {     this.year = year;     return this.http.get<Year>(`${this.informesNodes}`);   }    resetYear(year: any): Observable<Year> {     this.year = 'All';     return this.http.get<Year>(`${this.informesNodes}`);   } 

And my component

getYear(yearValue: any){     this.buscadorService.getYear(yearValue)     .subscribe((data: Year) => {       this.informesNode = data.data;       this.buscadorService.year = yearValue;       const attributes = this.informesNode.map((data: { attributes: any;}) => data.attributes);       attributes.filter((element: { ano: any; }) => element.ano === this.buscadorService.year);       this.buscadorService.pageNumber = 0;       this.nodeList = attributes;       console.log(this.nodeList);     });   } 

This is the best information i can provide, but feel free to ask if you need something so you can help me with this. Thanks in advance

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Decoupled Drupal Search JSON: API

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.