Deselecting every row in the px-data-table

I have integrated px-data-table into my Angular2 application. The data-table setup in my code looks like this:

<px-data-table #myTableRef [tableData]='tableDetails' language="en" (px-row-click)="selectedChanged($event)" (px-select-all-click)="selectAll($event)" sortable selectable show-column-chooser>
    <px-data-table-column *ngFor="let header of headers" type="html" name="{{header.value}}" label="{{header.label}}" [disableHide]="header.disableHide" [hide]="!header.disableHide">
    </px-data-table-column>
</px-data-table>

When a user selects multiple rows, the function selectedChanged($event) is triggered and the rows are highlighted. I am trying to figure out how to programmatically uncheck these selected rows, as opposed to relying on user interaction. I have attempted the following methods without success:

  1. Triggering the 'px-select-all-click' event from Angular using:

    this.myTableRef.nativeElement.fire('px-select-all-click')
    this.myTableRef.nativeElement.fire('px-select-all-click', this.myTableRef.nativeElement.selectedRows)
    // Even after invoking ChangeDetectorRef.detectChanges(), it did not yield the desired result.
    
  2. Targeting the checkbox with the ID 'selectAllCheckbox' from Angular with:

    this.myTableRef.nativeElement.shadowRoot.querySelector('selectAllCheckBox')
    this.myTableRef.nativeElement.querySelector('selectAllCheckbox')
    // Both return null, preventing me from proceeding with .click()
    
  3. Clearing the selectedRows attribute:

    this.myTableRef.nativeElement.selectedRows = [];
    

Unfortunately, none of the above methods proved successful. Upon inspecting the aha-table.html imported within px-data-table.html, I discovered a useful method: _setAllRows(e), which deselects all rows when called with _setAllRows(false). If only this method were accessible or callable from Angular, it would provide a solution to my problem of unchecking selected rows.

If you have any suggestions or solutions, they would be greatly appreciated.

Answer №1

Upon observing that the _setAllRows(e) method belongs to the aha-table component nested within the px-data-table component, accessing this method is straightforward as per the Polymer documentation on the Local DOM API.

let tableRef = this.myTableRef.nativeElement;
tableRef.$$('aha-table')._setAllRows(false);

In essence, $$('selector') serves as the Polymer shortcut for dynamically generated nodes. By obtaining the reference for the aha-table node, its methods can be easily invoked.

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

Finding the index number of a DIV element when it is clicked

Here is an example of the HTML structure I am working with: <div id="preview-wrapper"> <div class="dz-preview dz-image-preview"> <a class="rotate-a" href="javascript:void(0);"> <img class="rotate" src="public/a ...

Utilizing fab-icons with CDN in Next.js version 13.4

Currently, I am working with the latest version of Next.js (13.4) and I would like to incorporate a single Icon into my project using Font Awesome CDN to avoid increasing the overall app size. However, when I include the following code snippet in my layou ...

Are the Angular App routerlinks functioning properly in development but encountering issues in the production environment?

Every time I execute the command npm start, my Angular application works perfectly as intended. However, when I attempt to build it in "prod" mode, my application doesn't seem to function properly. It only displays a static page. All navigation link ...

Iterate through the elements in an array in order to generate new elements

Currently, I am in the process of comparing various popular javascript frameworks and I need to generate an HTML element for each object retrieved from an API. const frameworks = [ { name: "angular" }, { name: "ember" }, { name: "rea ...

How to dynamically set a computed background image in Vue 2

I have several divs that I want to style with backgrounds from values stored in an array. My attempt to set the background overlay for each one by creating a computed property has not been successful: computed: { backgroundImage(url) { let ...

What are the primary purposes of the site.webmanifest file?

As I navigate through an HTML Boilerplate, I come across a file named site.webmanifest. Despite my efforts to research its purpose online, I am still unclear about its significance. Could this file be essential for website development? What are the specif ...

Creating dynamic meta tags in Angular using server side rendering

I have developed an Angular application with Server-Side Rendering. Before deploying the final result to Azure SWA, I utilize the prerender command. One of the components in my application is a blog post component, and here is the code snippet: import { C ...

Tips for triggering a function when the range slider is adjusted

I'm looking to trigger a function whenever a user changes a range slider in my Vue.js project, and I also need to pass the new value to that function. The code snippet below shows what I have so far. <div cla ...

Comparing AngularJS and AppML

As a beginner in AngularJS and AppML, I am curious to understand the strengths and differences between these two frameworks. Despite some similarities I noticed on W3Schools, I'm eager to dive deeper into each one's unique features. ...

Guide to capturing user input in an Express router after it has been initialized

I currently have the following components in my project: - An app.js file that utilizes the routes specified in index.js - An index.js file where the initial SQL data retrieval is performed - An index.pug file containing a form to collect user input, in ...

What is the process for closing the side menu by clicking on the dark area?

I created a basic side navigation menu. When you resize the window to a smaller size, a red square will appear. If you click on this red square, the menu will open. The menu opens correctly, but I want it to close when I click on the dark area instead of ...

What is the ideal way to utilize Vue within the framework of multiple pages?

When using the default Vue CLI setup, Vue is loaded from the index.html page. To work with Vue and dynamic content on the page, everything is typically handled in the App.vue file. But what if you want to make significant layout changes to the page? How d ...

"Revolutionizing Form Building with Angular 6 Dynamic Select S

I have been utilizing Angular6 JSON Schema Form for my project. I have a situation where an html select element is defined using JSON: { "schema": { "type": "object", "title": "My Form", "properties": { "select1552420741389": { "type": ...

Transfer information from one Angular JS page to another pager based on ID

In my use of the mobile angular js UI framework, I am a beginner in angular js and looking to transmit data from one page to another using city id. When a user clicks on a city, the data should be displayed according to that specific city. HOME PAGE: ht ...

What is the best way to retrieve an array element from outside a function?

Is there a way to access the distance and pos elements outside of the function in this code snippet? navigator.geolocation.getCurrentPosition(function(position) { var pos = { lat: position.coords.latitude, lng: position.coords.longit ...

Is there a way to customize the look of the time selected in the <input matInput type="time" step="1" /> time picker?

Currently, I am utilizing the following code as a time picker in my Angular 9 application. My goal is to modify the selected time's color to a bright blue shade. How can I accomplish this task? <input matInput type="time" step="1&quo ...

The chai property "matchSnapshot" is not valid

https://i.sstatic.net/4wgqq.png After following the instructions provided at this link, I am now in the process of writing basic Jest tests for my React application that uses the Create-React-App starter kit. I came across a recommendation mentioned here ...

Learn how to iterate over a JSON object using TypeScript in Angular5 to generate an array of objects

Here is a sample JSON code that includes an array "Customers" with objects and arrays nested inside: This is my JSON code snippet: { "Customers": [ { "customerData": { "secondLastName": "Apale", "firstLastName": "Lara", ...

Injecting Vue.JS data into an HTML attribute

I'm currently exploring Vue.JS and working on a status bar. I am curious about how to incorporate data from Vue into an HTML attribute. <div class="progress"> <div class="progress-bar" role="progressbar" aria-valuenow="score" aria-valuem ...

ReactJS Provider not passing props to Consumer resulting in undefined value upon access

Hey there! I've been facing an issue with passing context from a Provider to a consumer in my application. Everything was working fine until suddenly it stopped. Let me walk you through a sample of my code. First off, I have a file named AppContext.t ...