Hello Senthil,
I'm not totally sure how you created your solution but for a customer we used a similar approach as mentioned in these articles:
Starting article
https://medium.com/@benjaminsgriggs/how-to-create-efficient-dynamic-queries-in-mendix-cc7a4b51ea53
Follow up article
https://medium.com/@benjaminsgriggs/how-to-create-a-custom-grid-in-mendix-485eed39bc97
Datagrid as Datagrid2 were in our case not covering all requirements so we build our own. With the java actions the retrieves are handled very quick. Side note; make sure you optimize your queries optimal according to the best practices whenever you are using a normal retrieve activity or a java action.
Hope this offers some insight, good luck.
Thijs