filter or sorting in gridView

Hi I made CRUD and in the index I display the data along with the image. But I wanted to ask what I can do to display the data according to the formula.

Namely, I have here a table "Categories".

In this table Rel_Category is the same as Id. For example: ‘test’ where id = 54 is a category that has a subcategory: ‘test2’ and ‘category’ (id = 51 and 53). In Index I would like to see this data to the following were subcategories, namely under ‘test’ show up ‘category’ and ‘test2’. I hope that I explain this fairly comprehensive. I do not know where to start probably need to write something in the $ DataProvider? Can someone help?