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
close icon

Update grid datasource without going back to page 1

Hello,

I have a Grid (defined using MVC helpers) which displays some data that is periodically updated from a ajax call. 

The problem is that when I update the datasource (via typescript), the grid goes back to page one. I don't want this behaviour, I want the grid to stay to the same page (number of elements/pages will always remain the same). Is there any built-in functionality to make this? Or some way to save the page number and re-set it to after the datasource update (or maybe in the same ejGrid,({...}) call)?


This is the code that updates the datasource:

$.getJSON("/Tracking/GetTrackingBufferByZone", obj2Send,
                (data: TrackingDataVM, status, xhr) => this.bufferGridEl.ejGrid({ dataSource: data })
                );

(this.bufferGridEl is the jQuery element of the grid)


Thank you.

3 Replies

GV Gowthami V Syncfusion Team July 1, 2015 12:40 PM UTC

Hi Antonio,

Thanks for using Syncfusion products.

We have analyzed your requirement and we can get the current page index details using “currentPage” property of the pageSettings of the grid as follows.

  <script type="text/javascript">

//Creating instance for grid

var gridObj = this.bufferGridEl.data("ejGrid");

            //Getting current page number value using pageSettings property before updating the datasource

            var currentPage = gridObj.pageSettings.currentPage;

            $.getJSON("/Tracking/GetTrackingBufferByZone", obj2Send,

                //Set the current page number through set model
                (data: TrackingDataVM, status, xhr) => this.bufferGridEl.ejGrid({ dataSource: data , pageSettings: {currentPage: currentPage }});   </script>


Please refer the below documentation link for more clarification.

http://help.syncfusion.com/UG/JS_CR/ejGrid.html#pageSettings

We can also set the page number using the method “gotoPage” and also please refer the below link for more clarification.

http://help.syncfusion.com/UG/JS_CR/ejGrid.html#gotoPage

If we misunderstood your requirement please provide more details about your requirement like screenshot or in which event/scenario you are updating the data source. The provided information will help us to analyze the issue and provide you the response as early as possible.

Regards,
Gowthami V.


AP Antonio Pretto July 2, 2015 08:09 AM UTC

Hi Gowthami,

thank you for your greate answer.

The code looks straight-forward, I should have looked in the docs by myself.

But I have an issue with your code: the object returned by 
this.bufferGridEl.data("ejGrid");
has no "pageSettings" property. Looking a bit in the object, I found that "pageSettings" was inside "model"

Also, setting datasource and pagesettings at the same time won't work: the page wil be resetted to 0

At the end, the following code works:

            var gridObj = this.bufferGridEl.data("ejGrid");
            var currPage = gridObj.model.pageSettings.currentPage;

            $.getJSON("/Tracking/GetTrackingBufferByZone", obj2Send,
                (data: TrackingDataVM, status, xhr) => {
                    this.bufferGridEl.ejGrid({ dataSource: data });
                    this.bufferGridEl.ejGrid({ pageSettings: {currentPage : currPage} });
                });











GV Gowthami V Syncfusion Team July 3, 2015 12:32 PM UTC

Hi Antonio,

Sorry about the inconvenience caused.

Query 1: But I have an issue with your code:

We have mistakenly updated the code snippet for getting currentPage directly from the grid instance instead of from the grid’s model.

Now we are happy that you have found the correct code and resolved the issue.

Please get back to us if you need further assistance. We will happy to assist you.

Query 2: setting datasource and pagesettings at the same time won't work: the page wil be resetted to 0

We have analyzed your issue and we are unable to reproduce the reported issue “setting datasource and pagesettings at the same time won't work”.

Please share us below details for reproducing the reported issue.

1.     Share us the product version details.

2.     And share us the code snippet that you have tried in your application.


The provided information will help us to analyze the issue and provide you the response as early as possible.

Regards,
Gowthami V.


Loader.
Live Chat Icon For mobile
Up arrow icon