Grid checkbox

Hello,

I want to allow the user to select only one checkbox , and if it selects another checkbox the one selected before to be deselected.

How can I achieve this?

Thank you in advance.



3 Replies

PS Pavithra Subramaniyam Syncfusion Team May 20, 2022 12:05 PM UTC

Hi Dana Sarghe,


Greetings from Syncfusion.


By default, Checkbox selection is used for multiple Grid row selection. So, if you want to maintain only one selected row at a time, You can achieve your requirement by using the “rowSelecting” event of Grid component. Please refer to the below code example, documentation link and sample link.


[component.ts]

@Component({ 

    selector: 'app-root', 

    templateUrl: ' <ejs-grid #grid [dataSource]='data' allowPaging='true' [allowSelection]="true" [editSettings]='editSettings' (rowSelecting)='rowSelecting($event)'

        <e-columns> 

            <e-column type='checkbox' width='50'></e-column> 

             .   .  . 

        </e-columns> 

    </ejs-grid> ', 

}) 

export class AppComponent { 

    .   .  . 

    rowSelecting(e){ 

      if(this.grid.getSelectedRecords().length){  

        this.grid.clearSelection();  

      }  

    } 

 


Documentation: https://ej2.syncfusion.com/angular/documentation/api/grid/#rowselecting


                              https://ej2.syncfusion.com/angular/documentation/api/grid/#getselectedrecords

                              https://ej2.syncfusion.com/angular/documentation/api/grid/#clearselection


Sample               : https://stackblitz.com/edit/angular-z9wemm?file=app.component.html,app.component.ts


Please get back to us if you need further assistance.


Regards,

Pavithra S



DS Dana Sarghe May 23, 2022 06:52 AM UTC

Hello,

This solution works just perfect for my requirement.

Thanx!



PS Pavithra Subramaniyam Syncfusion Team May 24, 2022 07:23 AM UTC

Hi Dana Sarghe,


Most Welcome! We are glad to hear that the provided solution works. Please get back to us if you need further assistance on this.


Regards,

Pavithra S


Loader.
Up arrow icon