Show a div while rows have been selected - Checkbox Selection

Hi,

I'd like to show a div that remains persistent (displayed) while any row in the grid is selected. And when all rows have been deselected, the div should hide again.

Been trying this for a few hours now, and have gotten to the point where I can show the div using rowSelected, but when I try to hide it that's where I'm getting stuck!

1 Reply

RS Rajapandiyan Settu Syncfusion Team April 7, 2020 02:00 PM UTC

Hi Glen, 
 
Greetings from syncfusion support. 
 
Query : I'd like to show a div that remains persistent (displayed) while any row in the grid is selected. And when all rows have been deselected, the div should hide again. 
 
From your query we could see that you need to show and hide a div element when the  grid selection and no selection occurs.  You can achieve this by using the Grid’s rowSelected ( Triggers after a row is selected ) and rowDeselected ( Triggers when a selected row is deselected ) events. Please refer the below code example and sample for more information. 
 
<div id='customdiv'>row is selected</div> 
<ejs-grid #grid [dataSource]='data' (rowSelected)="rowSelected($event)" (rowDeselected)="rowDeselected($event)"> 
  <e-columns> 
  <e-column field='OrderID' width='120'></e-column> 
  <e-column field='CustomerID' width='120'></e-column> 
  <e-column field='ShipCity' width='120'></e-column> 
  </e-columns> 
</ejs-grid> 
 
<style> 
  #customdiv{ 
    display:none;  // initially div element is hided 
  } 
  </style> 
 
 
export class AppComponent implements OnInit { 
 
  @ViewChild('grid',{static:true}) public grid: GridComponent; 
   public data: object[]; 
     
    ngOnInit(): void { 
     this.data = hierarchyOrderdata; 
    } 
    rowSelected(args){ 
// show the div element when grid selection occurs 
       document.getElementById('customdiv').style.display = 'block'; 
    } 
    rowDeselected(args){ 
      if(this.grid.getSelectedRecords().length == 0){ 
// hide the div element when no selection occurs in grid 
      document.getElementById('customdiv').style.display = 'none'; 
      } 
    } 
} 
 
 
 
 
 
Please get back to us if you need further assistance on this. 
 
Regards, 
Rajapandiyan S

Loader.
Up arrow icon