We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Reset page to 1 for a data grid

Hi I am using the MVC Grid control with data binding. I find that the page number won't be reset after changing of the sort item, I would like to reset the page index to the very first page (i.e. page 1) after sorting/filtering and I wonder what is the proper way to implement this feature? BTW, I think that the client side event ActionBegin is not being fired if the grid has invoked EnablePersistence inside the view.

3 Replies

AS Alan Sangeeth S Syncfusion Team April 29, 2015 03:48 AM UTC

Hi William,

Thanks for using Syncfusion Products.

Query 1: “After filtering/sorting, Grid must move to first move page”
We are glad to let you know that we have achieved your using “ActionBegin” Grid event in which when the request from Grid is Filtering or sorting we have updated the current page to 1. Please refer the following code snippets.

(Html.EJ().Grid<EJGrid.Models.EditableOrder>("Grid")

...

ClientSideEvents(eve => eve.ActionBegin("beginHandler"))

)


<script>

function beginHandler(args) {

if(args.requestType =="sorting" || args.requestType == "filtering")

this.model.pageSettings.currentPage = 1;

}

</script>



For your convenience we have created a sample and the same can be downloaded from below link.
Sample: http://www.syncfusion.com/downloads/support/forum/118942/EJGrid1182064056.zip

Query 2: “ActioBegin event not triggers when “EnablePersistence” is enabled”

We regret to let you know that we are unable to reproduce the issue in our end. We have created the above provided sample with “EnablePersistence” enabled in the sample and it is working fine.

Could you please let us know more information about the issue such as the scenario, Grid code snippets or if possible, reproduce the issue in the above sample and send us back so that we could provide you a response as early as possible?

Please let us know if you need any further assistance.
Regards,
Alan Sangeeth S


BF Bruno Figueiredo December 4, 2017 04:50 PM UTC

Hi,

I had the same question and while searching for an answer, I found this thread.

My grid has a different datasource and has virtual loading.
I have everything working ok but when I go to, for example,  the 3rd virtual page and then hit some column to Sort, the request to the server only returns one page, and is the  3rd page, and the grid shows some empty results and then the sorted 3rd page.
You can see this in the "broken sort.PNG"

If you can help me with this I appreciate.

But to fix this behaviour I thought to go to the first page when sorting/filtering, so I end up here.
I added the this.model.pageSettings.currentPage = 1;  in the ActionBegin and, in the controller, the DataManager.Skip is == 0, so it returns the first page only., but the scrollbar has a weard behaviour.
It does not go to the start  when I hit sort.
 In the "first search.PNG" is the grid after the first search. everything ok
In the "before sort.PNG" is the grid in the 3rd page and everything is still ok.
In the "after sort.PNG" you can see the grid, in the 1st page BUT the scroll is in a random(?) position. why? can I force the scroll go to the first record?


My grid in the cshtml:
 .Datasource(d => d.URL("/mycontroller/DoVirtualSearch").Adaptor("UrlAdaptor"))
            .IsResponsive(true)
            .EnableResponsiveRow(false)
            .AllowSorting()
            .ScrollSettings(s => s.AllowVirtualScrolling().VirtualScrollMode(VirtualScrollMode.Continuous).Height(400))
            .SortSettings(sort => sort.SortedColumns(col => col.Field("Date").Direction(SortOrder.Descending).Add()))
            .MinWidth(650)
            .AllowSelection()
            .AllowScrolling(true)
            .ClientSideEvents(e => e.ActionBegin("ActionBegin"))
            .AllowResizing()
            .AllowFiltering()
            .FilterSettings(filter => { filter.FilterType(FilterType.Excel); })


And the controller:

public ActionResult DoVirtualSearch(DataManager dm, SearchModel model)
        {
            List<SearchRecord> list = MyService.Search(model);

            DataResult result = new DataResult();
            DataOperations operation = new DataOperations();
            result.result = list;
            if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting 
            {
                result.result = operation.PerformSorting(result.result, dm.Sorted);
            }
            if (dm.Where != null && dm.Where.Count > 0) //Filtering 
            {
                dm.Where.ForEach(f => f.Operator = "contains");

                result.result = operation.PerformWhereFilter(result.result, dm.Where, "contains");// dm.Where[0].Operator);
                result.count = result.result.Cast<SearchRecord>().Count();
            }
            else
            {
                result.count = result.result.Cast<SearchRecord>().Count();
            }
            if (dm.Skip != 0)
            {
                result.result = operation.PerformSkip(result.result, dm.Skip);
            }
            if (dm.Take != 0)
            {
                result.result = operation.PerformTake(result.result, dm.Take);
            }
            return Json(result, JsonRequestBehavior.AllowGet);

        }

Attachment: PNGs_2dfb154b.zip


VA Venkatesh Ayothi Raman Syncfusion Team December 7, 2017 03:47 PM UTC

Hi Bruno, 
 
Thanks for the update. 
 
We are able to reproduce the reported issue at our end and we have considered this “Sorting is not working while using virtual scroll mode as continuous” as bug and fix for this issue will be included in our upcoming Volume 4,2017 release which is expected to be rolled out in the month of December,2017. 
 
Until we suggest to you use Virtual scroll mode as Normal for your requirement. 
 
Regards, 
Venkatesh Ayothiraman. 


Loader.
Live Chat Icon For mobile
Up arrow icon