Regarding Execute Query() GroupBy Field


I am having a form which contains a Datasource name of Table3, it has 3 fields ( Days, LastDoneDate, NextScheduleDate )

the Table Contains the following Record

LastDoneDate NextScheduleDate Day
1/1/2012 1/6/2013 20.00
1/1/2011 1/5/2013 10.00
1/1/2011 1/5/2013 10.00

in the Form i have to show the Record as GroupBy the Three fields.

same way i have written the coding in Datasource ExecuteQuery

public void executeQuery()
this.query().dataSourceName(‘Table3’).addGroupByField(fieldnum(Table3, Days));
this.query().dataSourceName(‘Table3’).addGroupByField(fieldnum(Table3, LastDoneDate));
this.query().dataSourceName(‘Table3’).addGroupByField(fieldnum(Table3, NextScheduleDate));

It;s showing me the perfect Output in the Form Grid as GroupBy, it showing 2 records as data as available in Table…

But the Problem is when im Sorting the Form Grid The Records are not Showing as GroupBy . Its showing the Entire 3 records.

Please tel me where i have done Mistake

Once you sort the form, it would get refreshed and groupby changes. You can reopen the form.

But how to avoid it, I have to show the data always GroupBy in that Grid, Even if it Sort . How to achieve this