question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Header's Select All checkbox breaks "selected" model binding

See original GitHub issue

I’m submitting a … (check one with “x”)

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, post on Stackoverflow or Gitter

Current behavior When I check the header’s “Select All” checkbox, the [selected] model is not updated and never updated again.

When I check individual rows, the selected model is updated as long as I do not check the header’s Select All.

The footer’s selected count is still updated as expected.

Handling the (select) output with the splice/push combo as in the demo, is the way around it, but the documentation is pretty unclear.

Note: Maybe related to #818, I’m unsure…

Expected behavior The header’s “Select All” checkbox should update the selected model.

Reproduction of the problem I reproduced it here: https://plnkr.co/5NHahUqqU1NVW2dH

ezgif com-video-to-gif

What is the motivation / use case for changing the behavior? It really looks broken… it half works, then stops without any error message in the logs.

Please tell us about your environment:

  • Table version:@swimlane/ngx-datatable”: “^13.1.0”

  • Angular version: Angular 6.1.3

  • Browser: Tried in Chrome 68.0.3440.106 and Edge 42.17134.1.0

  • Language: All

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:8
  • Comments:7

github_iconTop GitHub Comments

3reactions
dstjcommented, Jan 18, 2019

@james-poulose, as mentioned in the original issue:

Handling the (select) output with the splice/push combo as in the demo, is the way around it, but the documentation is pretty unclear.

i.e. this one: http://swimlane.github.io/ngx-datatable/#chkbox-selection

And the relevant code is:

  onSelect({ selected }) {
    console.log('Select Event', selected, this.selected);

    this.selected.splice(0, this.selected.length);
    this.selected.push(...selected);
  }
0reactions
Arti3DPlayercommented, Mar 8, 2021

https://user-images.githubusercontent.com/3278913/110382838-2291d680-8064-11eb-995b-814a17cedf38.mov

My onSelect method:

onSelect({selected}) {
        this.selectedInvoiceItemGroups.splice(0, this.selectedInvoiceItemGroups.length);
        this.selectedInvoiceItemGroups.push(...selected);
    }

My datatable:

<ngx-datatable
                                    class="material striped"
                                    [rows]="invoiceItemGroups"
                                    [columnMode]="ColumnMode.force"
                                    [headerHeight]="headerHeight"
                                    [rowHeight]="'auto'"
                                    [footerHeight]="50"
                                    [limit]="15"
                                    [externalSorting]="true"
                                    [selected]="selectedInvoiceItemGroups"
                                    [selectionType]="SelectionType.checkbox"
                                    (sort)="onSort($event)"
                                    (select)="onSelect($event)"
                                    [sorts]="[{prop: storedParams.ordering.replace('-', ''), dir: (storedParams.ordering.startsWith('-')) ? 'desc' : 'asc'}]"
                                    [loadingIndicator]="invoiceItemGroupsIsLoading" #invoiceDatatable>

                                <ngx-datatable-column [width]="40"
                                                      [sortable]="false"
                                                      [canAutoResize]="false"
                                                      [draggable]="false"
                                                      [resizeable]="false">
                                    <ng-template ngx-datatable-header-template let-value="value"
                                                 let-allRowsSelected="allRowsSelected" let-selectFn="selectFn">
                                        <input type="checkbox" class="customCheckbox" [checked]="allRowsSelected"
                                               (change)="selectFn(!allRowsSelected)"/>
                                    </ng-template>
                                    <ng-template ngx-datatable-cell-template let-value="value" let-isSelected="isSelected"
                                                 let-onCheckboxChangeFn="onCheckboxChangeFn">
                                        <input type="checkbox" class="customCheckbox" [checked]="isSelected"
                                               (change)="onCheckboxChangeFn($event)"/>
                                    </ng-template>
                                </ngx-datatable-column>
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Select All CheckBox of a Column by DataGrid Header ...
The first problem is that you can't just bind the view model to the column header because it doesn't have the view model...
Read more >
How to customize select all checkbox behavior in grid header
This Knowledge base explains how to customize the behavior of the header checkbox when checkbox selection is used. Solution:.
Read more >
Multi-select ASP.NET Core Tags - GrapeCity
Multi-select control supports the following ASP. ... selected-item; selected-value; selected-value-path; select-all-label; show-select-all-checkbox ...
Read more >
List Selection - DevExtreme List: JavaScript Components by ...
The showSelectionControls property should also be enabled when you use the "all" selectionMode to show the Select All checkbox. When the List data...
Read more >
Keyboard shortcuts – Notion Help Center
Use shift + click to select another block and all blocks in between. Press backspace or delete to delete selected blocks. Press cmd/ctrl...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found