Solution: Datatable mutilselect click to toggle rows

UI Components for Angular
Post Reply
pvandenboogaard
Posts: 10
Joined: 20 Jun 2016, 09:09

22 Jun 2016, 11:29

Maybe someone will find it usefull.
Bind selectedRows to the datatable.
(uses lodash)

Code: Select all

public selectedRows: Array<any>;
public _selectedRows: Array<any> = [];

onRowSelect(event) {
    let i = _.findIndex(this._selectedRows, (row) => {
      return row != null && row.Id != undefined ? row.Id == event.data.Id : false;
    });
    if (i != -1) {
      this._selectedRows.splice(i, 1);
    }
    else {
      this._selectedRows.push(event.data)
    }
    this.selectedRows = this._selectedRows;  }

bleh910
Posts: 8
Joined: 23 Jun 2016, 19:15

23 Jun 2016, 19:20

Thanks a lot for posting this solution. Its a feature I require to build my application.

However I am getting the error ._findIndex is not a function error. I have included the below CDN in index.html - "https://cdn.jsdelivr.net/lodash/4.13.1/ ... ore.min.js".
Could you let me know if there is anything else I need to do?

I know this may be a silly question but I am new to Angular 2 and Typescript , and have worked very little with Javascript.

pvandenboogaard
Posts: 10
Joined: 20 Jun 2016, 09:09

27 Jun 2016, 16:19

Add the following to the top of your .ts file
import * as _ from 'lodash';

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

27 Jun 2016, 17:55

So this enabled multi select row without having metakey? Maybe we can reimplement it to use this approach instead of metakey. Is this related to;

https://github.com/primefaces/primeng/issues/284

pvandenboogaard
Posts: 10
Joined: 20 Jun 2016, 09:09

28 Jun 2016, 09:50

Yes, this allows to multi select with only using the LMB.

My experience is that this is more natural for the average user, not having to use the ctrl key.
Which half don't even know about probably.

Also this allows to multi select on different pages when using paging, i don't think that's possible with the current implementation (but i could be wrong there, haven't tried)

also, pressing ctrl on a touch screen device might be tricky.

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 27 guests