Get currentViewData Indexes

Is there a way to get the indexes for Grid.CurrentViewData, so I can set them selected e.g.?


1 Reply

PG Praveenkumar Gajendiran Syncfusion Team October 18, 2021 12:24 PM UTC

Hi Sebastian,

Greetings from Syncfusion support.

We checked your query, based on that we suspect your requirement is to select the rows based on currentViewData values. For this, we suggest you to pass the currentViewData primaryKey value to the Grid’s getRowIndexByPrimaryKey method to get that row index and then pass the row index to the Grid’s selectRows method to the select those rows in the Grid as demonstrated in the below code example.

Code Example: 
 let genarateDataButton = new Button({}, '#select'); 
genarateData.element.onclick = () => { 
  var data = grid.currentViewData; 
  var rowIndex = []; 
  data.forEach((d=> { 
    if (d['Title'] == 'Sales Representative') { 
      var index = grid.getRowIndexByPrimaryKey(d['EmployeeID']); 
      rowIndex.push(index); 
    } 
  }); 
  grid.selectRows(rowIndex); 
}; 
 
let gridGrid = new Grid({ 
  dataSource: employeeData, 
  allowSelection: true, 
  selectionSettings: { type: 'Multiple' }, 
  enableHover: false, 
  columns: [ 
    { 
      field: 'EmployeeID', 
      headerText: 'Employee ID', 
      textAlign: 'Right', 
      width: 135, 
      isPrimaryKey: true, 
    }, 
    { field: 'FirstName'headerText: 'Name'width: 125 }, 
    { field: 'Title'headerText: 'Title'width: 180 }, 
    { 
      field: 'HireDate', 
      headerText: 'Hire Date', 
      textAlign: 'Right', 
      width: 135, 
      format: { skeleton: 'yMd'type: 'date' }, 
    }, 
  ], 
}); 
grid.appendTo('#Grid'); 


 
We have prepared a sample based on this for your reference. You can find it below, 



If we misunderstood your query or if you require any further assistance, then please get back to us. 

Regards, 
Praveenkumar G 


Loader.
Up arrow icon