Having trouble getting the p-columnFilter to work with p-multiSelect in my Primeng Angular table

Could someone assist me in troubleshooting why my multiselect filter is not functioning correctly? The multiSelect displays the different options accurately, showing values from the "direction" column. However, when I select any value from the options, all rows in the table disappear as if the keyword is not present in any row within the "direction" column.

I am puzzled about this issue and uncertain about how exactly this p-multiSelect works, especially since the documentation lacks details. I have set it up precisely as shown here: https://www.primefaces.org/primeng/table/filter

The data in the column for the field direction appears like this ['SW', 'N', 'SW', 'NE'....] (24 strings in array)

This is HTML

<th pSortableColumn="direction">Wind Direction <p-sortIcon  field="direction"></p-sortIcon>
            <p-columnFilter field="direction" matchMode="in" display="menu" [showMatchModes]="false" [showOperator]="false" [showAddButton]="false">

              <ng-template pTemplate="filter" let-value let-filter="filterCallback">
                  <p-multiSelect [ngModel]="value" [options]="windDirections" placeholder="Any" (onChange)="filter($event.value)" optionLabel="direction">
                      <ng-template let-option pTemplate="item">
                          <div class="p-multiselect-wind-option">
                            <span class="pi pi-compass mr-5px"></span>
                            <span style="margin-left: 5px;">{{option.direction}}</span>
                          </div>
                      </ng-template>
                  </p-multiSelect>
              </ng-template>
          </p-columnFilter></th>

Here is TypeScript code


  windDirections: Wind[];

this.windDirections = [    // options for the multiselect filter
      new Wind('N'),
      new Wind('NE'),
      new Wind('NW'),
      new Wind('S'),
      new Wind('SW'),
      new Wind('SE'),
      new Wind('E'),
      new Wind('W'),
    ];

// wind model
export class Wind {
  constructor(public direction: string) {}
}

// Function formatting the wind direction column based on the direction 

checkWindDirection(value) {
    if (value >= 0 && value <= 22) {
      return new Wind('N').direction;
    } else if (value > 22 && value <= 67) {
      return new Wind('NE').direction;
    } else if (value > 67 && value <= 112) {
      return new Wind('E').direction;
    } else if (value > 112 && value <= 157) {
      return new Wind('SE').direction;
    } else if (value > 157 && value <= 202) {
      return new Wind('S').direction;
    } else if (value > 202 && value <= 247) {
      return new Wind('SW').direction;
    } else if (value > 247 && value <= 292) {
      return new Wind('W').direction;
    } else if (value > 292 && value <= 337) {
      return new Wind('NW').direction;
    } else return new Wind('N').direction;
  }

// Subscribing to the function within ngOnInit which formats the wind direction based on a certain condition

const windDirections =
          historicalWeatherData.hourly.winddirection_10m.map((item) =>
            this.checkWindDirection(item)
          );

If I switch the multiselect filter to a basic text filter, it filters based on what I type. However, the multiselect picker filter does not seem to be working.

Answer №1

After some troubleshooting, I quickly discovered the issue. By including the

optionValue="direction"
attribute in the p-multiselect element, the functionality is now functioning as expected!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Looking for the type definition file for the xss-clean npm library?

Recently, I embarked on a journey to learn Typescript and began the process of converting my Node.js/Express application to use it. Thus far, I have managed to acquire all the necessary type definitions for libraries by running npm i @types/some-lib. The ...

Finding the amount of memory that can be used in a WebView

I'm currently developing an application that features a WebView running JavaScript code. This particular JavaScript code tends to be memory-intensive and can sometimes exceed the allotted memory, leading to crashes in the WebView's Chromium proce ...

Angular is getting hung up on the process of "reloading client(s)" and failing to properly refresh the page

As a React developer, I've decided to start learning Angular. I created a new project using "ng new my-first-app", but I'm facing an issue with hot module reload. It stops working shortly after I make changes to the "app-component.html" file and ...

Leverage AJAX for real-time Django Model updates

Seeking insights on how to effortlessly update a Django model through AJAX without reloading the page or requiring user input for saving. Various tutorials address fetching data from Django models using AJAX, yet resources on updating models remain scarce. ...

The dateBefore function in Angular is throwing an error: TypeError saying that value does not have a getTime function

Hello everyone, hope you're having a good afternoon. I'm running into an issue while trying to set up a filter on the date table. Every time I attempt to do so, an error pops up. Here's a glimpse of the error: https://i.sstatic.net/PuYMr. ...

Eliminate the bold frame surrounding the input textbox

Objective: I want to remove the bold frame around the input textboxes, while maintaining a simple and single frame appearance. Issue: The boldness of the input textbox frame becomes prominent when using CSS code related to background-image, background ...

In Angular, I aim to invoke the this.addDispatchToReceive method whenever the outcome is successful within each forEach iteration

How can I ensure that the values from this.stockItemDispatch are obtained in this.addDispatchToReceive(); during each iteration of a loop, instead of only getting the last stock value? The issue is that the subscribe function runs after the foreach cycle ...

Canvas: add a translucent layer covering the entire canvas, leaving one window untouched

I'm working on a project where I have a rectangular canvas with an image on it. I want to implement a cool effect where, as the user hovers over the canvas, the whole canvas becomes semitransparent - except for a small rectangle around the cursor whic ...

Retrieve data from multiple documents in a MongoDB collection using a single API request

I have developed three separate MongoDB functions to retrieve data from different collections. // mongo DB models/user module.exports.countUsers = function (callback) { User.findOne().where({ 'status': 1}).count(callback); } ...

I encountered an issue while trying to integrate react-alert into my React application. An Uncaught Error was thrown, stating that objects are not valid as a React

I encountered the following error: react-dom.development.js:14748 Uncaught Error: Objects are not valid as a React child (found: object with keys {$$typeof, render}). If you meant to render a collection of children, use an array instead. in Unknown (c ...

Refreshing a Nested Component Within a Parent Component in React

Currently, I am in the final stage of a small project where a Higher Order Component (HOC) is being utilized to display a basic Tinder-like application. The internal component is a class-based component containing its own fetch() call that presents user d ...

The error message "Highcharts - Incompatible types of 'series' property" is displayed

When trying to create charts in Angular using Highchart, I encountered an error during compilation. The properties seem to be compatible, but the TypeScript compiler is throwing an error that I don't quite understand. Any suggestions on how to avoid t ...

During testing, the Vuetify expansion panel body is hidden with a display none style

Greetings! I am currently facing an issue while debugging my testing site. The problem is that the expansion panels are not displaying due to a style attribute attached to the div element of v-expansion-panel__body. Strangely, this issue does not occur on ...

How can I display the value of a variable within an Angular 4 component directly from the console?

In my Angular 4 component, I store a simple key in a variable. However, I am aware that when the app is closed, all values within the variable are erased. Here is an example of this: export class LoginComponent implements OnInit { data : any; const ...

Using Regular Expressions for validation restricts the functionality of home, end, and arrow keys

Issue: My HTML text input has a script that restricts input to alphanumeric characters in the onpress, onkeydown, and onkeyup events: this.value = this.value.replace(/[^a-zA-Z0-9]/, '') While this validation ensures only alphanumeric characters ...

How can a JavaScript file interact with a backend without needing to specify the URL in the compiled code, thanks to webpack?

Currently, I am working on a React application with webpack. After compiling the code using the command webpack --mode production && webpack --config webpack.config.prod.js I utilize a .env.prod file to specify the variable REACT_APP_BASE_URL, wh ...

Why is it that $_GET consistently returns null despite successfully transmitting data via AJAX?

I'm currently developing a PHP script that dynamically generates tables in MySQL based on user input for the number of rows and columns. The data is being sent to the server using AJAX, but even though the transmission is successful, the server is rec ...

I am currently implementing pagination for my data and it is functioning properly. However, I have noticed that when I search for specific data, it always appears on

My issue arises when I attempt to paginate my data and then search for specific information. The problem is that even if I am on page 3, the search results always display on page 1, making it difficult for me to locate the relevant data. What I want is for ...

Jquery and Magento Prototype causing conflicts

I am attempting to implement the Foundation 5 Reveal modal on a Magento product page. To do this, I have included jQuery and foundation.js in the footer and initialized Foundation from footer.phtml <script src="js/vendor/jquery.js"></script> ...

Check out the element using the browser's developer tools

There is a helpful feature in Google Chrome that allows you to take an element object from the console and easily jump to the corresponding element in the element inspector, potentially shown as a jQuery result set. This feature serves as the opposite of ...