I am using px-data-table in an Angular2 application. The data-table is used as follows:
<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>
The user selects more than one rows. So selectedChanged($event) is fired and multiple rows are selected. Now I'd like the selected rows to be unchecked from code not via user interaction. I went with the following approaches (which did not work):
Fire event 'px-select-all-click' from Angular by:
this.myTableRef.nativeElement.fire('px-select-all-click') this.myTableRef.nativeElement.fire('px-select-all-click', this.myTableRef.nativeElement.selectedRows) // also did a ChangeDetectorRef.detectChanges() after injection but it did not work.Select the checkbox with id 'selectAllCheckbox' from Angular by:
this.myTableRef.nativeElement.shadowRoot.querySelector('selectAllCheckBox') this.myTableRef.nativeElement.querySelector('selectAllCheckbox') //returns null in both cases so I can't do a .click() on itEmpty the selectedRows attribute:
this.myTableRef.nativeElement.selectedRows = [];
All three methods don't work.
I was looking inside the aha-table.html imported inside the px-data-table.html and found a convenient method: _setAllRows(e) which unselects all the rows with _setAllRows(false). If only this was exposed or I could call this from Angular, I'd have my solution to the problem: unchecking the selected rows.
Any solutions would be helpful.
After noticing that the
_setAllRows(e)is a method ofaha-tablewhich is a component nested underpx-data-tablecomponent, accessing the method is easy according to the Polymer documentation for Local DOM API.Basically
$$('selector')is the Polymer shorthand for dynamically created nodes. If I get the reference for theaha-tablenode, I can call its methods.