FlexGrid selected count

Posted by: bmakhlin on 2 July 2018, 10:45 am EST

  • Posted 2 July 2018, 10:45 am EST

    Hi,

    I need to display count of selected items in the FlexGrid in Angular 6 application. User can select all rows by clicking on checkbox in the header or click checkbox in the row. Total number of checked items need to be displayed. I found ink below for AngularJs. Is this recommended solution to figure out selected count in Angular 6 application? Should/Can I use wjFlexGridCellTemplate to display checkbox in the header (RowHeader)? If so, could you share an example?

    http://jsfiddle.net/mkgupta911/pq58z0yj/3/

    thank you

  • Posted 3 July 2018, 6:21 am EST

    Hi,

    If you are using angular then wjFlexGridCellTemplate is the recommended way to display cell templates.

    To select a row you can set isSelectedProperty of the row to true, then to get the selected rows you can iterate over rows and check if the isSelected property is set to true.

    Please refer to following code snippet

    /* appendcheckboxes in rowheaders */ 
    <ng-template wjFlexGridCellTemplate [cellType]="'RowHeader'" let-cell="cell"> 
    	<input type="checkbox" [(ngModel)]="cell.row.isSelected">
    </ng-template>
    /* attach checkall rows checkbox in topleft cell */
    <ng-template wjFlexGridCellTemplate [cellType]="'TopLeft'" let-cell="cell">
    	<input type="checkbox" [checked]="selectedRows.length>0"
    [indeterminate]="selectedRows.length!=0&&selectedRows.length<grid.rows.length" (change)="selAll(grid.rows,$event.target.checked,true)"> 
    </ng-template>
    
    /* get selected rows*/
    function getSelectedRows(grid){
    	let selRowIndices=[];
    	grid.rows.forEach(row=>{
    		if(row.isSelected){
    			selRowIndices.push(row.index);
    		}
    	});
    	return selRowIndices;
    }
    
    

    P.S. If the user is supposed to select only the rows and not cell ranges then please consider setting grid’s selectionMode property to ‘ListBox’. In LIstBox selection mode grid exposes selected rows via selectedRows property.

    Please refer to the following which implements the same:-

    https://stackblitz.com/edit/angular-p8kyyt?file=src%2Fapp%2Fapp.component.html

    ~Manish

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels