<DataGrid
                className="list"
                pagingation
                rows={registeredClasses} 
                columns={this.getColumns()}
                pageSize={10}
                rowLength={10}
                autoHeight
                // sortModel={sortModel}
                components={{
                  pagination:CustomPagination
                }}
                checkboxSelection
                onSelectionChange={(newSelection) =>{
                  console.log(newSelection)
                }}
                
               
              />
tried with onSelectionModelChange as well, selection is happening only if i click on row, if i click on checkbox it is not happening
onSelectionModelChange is now onRowSelectionModelChange. From the DataGrid API Docs:
Callback fired when the selection state of one or multiple rows changes.
function(
    rowSelectionModel: GridRowSelectionModel, 
    details: GridCallbackDetails 
) => void  
For more info, check out the DOCS HERE
Breaking changes were included with Version v4.0.0-alpha.34. onRowSelected has been removed and onSelectionModelChange now returns an array with indexes of the selected rows. You can alter the selection model directly via onSelectionModelChange:
import * as React from 'react'
import { DataGrid } from '@material-ui/data-grid'
import { useDemoData } from '@material-ui/x-grid-data-generator'
export default function ControlledSelectionGrid() {
  const { data } = useDemoData({
    dataSet: 'Commodity',
    rowLength: 10,
    maxColumns: 6,
  })
  const [selectionModel, setSelectionModel] = React.useState([])
  return (
    <div style={{ height: 400, width: '100%' }}>
      <DataGrid
        checkboxSelection
        onSelectionModelChange={(newSelectionModel) => {
          setSelectionModel(newSelectionModel)
        }}
        selectionModel={selectionModel}
        {...data}
      />
    </div>
  )
}
Updated Demo on Code Sandbox
Material UI Docs - Controlled Selection
Material UI DataTable Change Log on GitHub
Instead of
onSelectionChange={(newSelection) => {
    console.log(newSelection)
}}
Try onRowSelected, like so:
onRowSelected={(GridRowSelectedParams) => {
    console.log(GridRowSelectedParams);
}}
If you want to keep track of the selection state of all rows, you should use this:
onSelectionModelChange={(GridSelectionModelChangeParams) => {
    // This will return {selections: [selected row indexes]}
    console.log(GridSelectionModelChangeParams);
    if (Array.isArray(GridSelectionModelChangeParams.selectionModel)) {
        // Iterate the selection indexes:
        GridSelectionModelChangeParams.selectionModel.forEach(
            // Get the row data:
            (selection_index) => console.log(rows[selection_index])
        );
    }
}}
I set up a Code Sandbox with a working demo for you to try out
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With