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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Update grid datasource without going back to page 1

Thread ID:

Created:

Updated:

Platform:

Replies:

119484 Jun 30,2015 06:44 AM UTC Jul 3,2015 12:32 PM UTC ASP.NET MVC 3
loading
Tags: Grid
Antonio Pretto
Asked On June 30, 2015 06:44 AM UTC

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.

Gowthami V [Syncfusion]
Replied On 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.

Antonio Pretto
Replied On 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} });
                });










Gowthami V [Syncfusion]
Replied On 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.


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;