Implement checkbox in multiple columns inside grid, data not rendring according to datasource

Hi, I have tried to implement checkbox columns in ejs-grid, 
app.component.html

app.component.ts


the result i am getting is according to the first column only i.e. All column,


I also want to select the checkboxes according to conditions
1. If All of any row is selected, then all other columns should be checked
2. If any of the column (other than all) id unchecked, All should uncheck.

Thanks
Regards

3 Replies 1 reply marked as answer

AG Ajith Govarthan Syncfusion Team April 28, 2021 03:57 AM UTC

Hi Vaishali, 

Thanks for contacting Syncfusion support. 

Query: Implement checkbox in multiple columns inside grid, data not rendring according to datasource 

Based on your query you want to render the checkbox based the Grid dataSource. So, before we proceed to your query please share the below details to validate further on your requirement. 

  1. Please share the dataSource bound to the Grid component.

  1. Are you using same field data for all the checkbox templates?
 
  1. Please let us know that you have used Boolean data for checkbox templates.
 
  1. Share the syncfusion package version.
 
Regards, 
Ajith G. 



VG Vaishali Goyal April 28, 2021 04:48 AM UTC

Hi Ajith,
Thanks for you response, I have mentioned all the concers raised below: 
1. I have attached datasource file 
2. For now, I have implemented each chechbox template is for each of the feild present in the grid, (Is it possible to use same template for each feild, if that is possible it could help.)
3. Checkboxes have boolean data 
4. All the packages used are of the latest version.

I hope this solves all the queries.

Thanks 
Regards

Attachment: dataSource_b9a59ecd.rar


AG Ajith Govarthan Syncfusion Team April 29, 2021 02:29 PM UTC

Hi Vaishali, 

Thanks for the update. 

Query: Implement checkbox in multiple columns inside grid, data not rendring according to datasource. 
 
Based on your query you want to render the checkbox component as per the dataSource values with column template feature in your Grid application. So, we have prepared sample and in that we have used the column template feature to render the checkbox component on based on the dataSource values. 

We have also checked and unchecked all other checkboxes if any of the checkbox state is changed in the rows. For your convenience we have attached sample, please refer them for your reference. 

Code Example: 
App.component.html 

<div class="control-section"> 
  <ejs-grid #grid [dataSource]="data" [columns]="columns"> </ejs-grid> 

  <ng-template let-data #template1> 
    <ejs-checkbox 
      (change)="onChange($event)" 
      [checked]="data[data.column.field]" 
    ></ejs-checkbox> 
  </ng-template> 
</div> 


App.component.ts 

ngOnInit(): void { 
    this.columns = [ 
      { 
        field: "id", 
        headerText: "Employee ID", 
        width: "90" 
      }, 
      { field: "Template", headerText: "Template", width: "90" }, 
      { 
        field: "All", 
        headerText: "All", 
        width: "90" 
      }, 
      { 
        field: "Input", 
        headerText: "Input", 
        width: "90" 
      }, 
      { field: "View", headerText: "View", width: "90" }, 
      { 
        field: "MarkComplete", 
        headerText: "MarkComplete", 
        width: "90" 
      } 
    ]; 
  } 

  onChange(args) { 
    let row = parentsUntil(args.event.target, "e-row", false); 
    if (row) { 
      row.querySelectorAll(".e-checkbox").forEach(element => { 
        (element as any).ej2_instances[0].checked = args.checked; 
      }); 
    } 
  } 

  ngAfterViewInit(): void { 
    (this.grid.getColumns()[2].template as any) = this.temp1; 
    (this.grid.getColumns()[3].template as any) = this.temp1; 
    (this.grid.getColumns()[4].template as any) = this.temp1; 
    (this.grid.getColumns()[5].template as any) = this.temp1; 
  } 


Please get back to us if you need further assistance. 

Regards, 
Ajith G. 


Marked as answer
Loader.
Up arrow icon