How did you add the search button on DataGrid2? Is it a custom button? If yes, then you will have to build the logic for it.
If you want to use Mendix's out of the box search functionality, you need to use filters.
Add attributes you want to filter on through the 'Grid wide filterting' tab in your DataGrid2's properties.
You can then add the filters in the UI as Column filters or regular data filters.
I have a series of YouTube tutorials on DataGrid2, it might be helpful: