This is a migrated thread and some comments may be shown as answers.

Changing Count in Client-side binding moves you back to the first page

3 Answers 126 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 14 Jul 2009, 05:13 AM
My basic question is, every time the Count changes during client-side data binding, it jumps me back to the first page.  Is there any way to prevent this?

Here's a more in-depth description of the problem:

I'm using the RadGrid to display messages with client-side data binding.  A new message arrives on the server every few seconds.  We only keep x hundred messages on the server so once the queue is full old messages fall off the queue as new ones arrive.  Therefore using the standard startRowIndex to keep track of where we are in the grid doesn't work for us.  What is row 20 in one call might be row 19 a few seconds later as the oldest message falls off the queue.  Therefore simply want the next/previous/first/last buttons to jump to the next/previous/first/last group of messages and I'll handle the paging logic with my server code.

Toward that end, I have overridden (using OnItemCreated) the next/previous paging buttons to call my own javascript function for paging -
    function myGridPage(radGridId, dir) {
        pagingDirection = dir;
        $find(radGridId+'_ctl00').page(dir);
    }

Then on data binding I do this:
function RadGridMessages_DataBinding(sender, args) {
        var myMethodArguments = new Object();
        myMethodArguments.pagingDirection = pagingDirection;
        myMethodArguments.maximumRows = args.get_methodArguments().maximumRows;
        args.set_methodArguments(myMethodArguments);
    }

On the server-side I do this:
        [WebMethod(EnableSession = true)]
        public Dictionary<string, object> GetMessages(string pagingDirection, int maximumRows)
        {
<message logic goes here>
            Dictionary<string, object> data = new Dictionary<string, object>();
            data.Add("Data", messages);
            data.Add("Count", totalNumberOfMessages);
            return data;
        }

Everything seems to work fine, except that the "Count" changes often during the first few hours before the server message queue is full.  Every time the Count changes the Telerik client-side code calls set_virtualItemCount() which calls set_currentPageIndex(0).  This move me back to the first page (and triggers a rebind).

a. Am I handing the next/previous page in an appropriate way for my situation or is there a better way to do this.
b. How do I prevent set_virtualItemCount() from kicking me back to the first page every time the count changes?


3 Answers, 1 is accepted

Sort by
0
Matthew
Top achievements
Rank 1
answered on 14 Jul 2009, 05:02 PM
Can anyone explain how to override set_virtualItemCount()?  Javascript is not my primary language, I'm sure it's possible but I don't know how to go about it.
0
Nikolay Rusev
Telerik team
answered on 17 Jul 2009, 06:47 AM
Hello Matthew,

The behavior of resetting page index when virtualItemCount has changed is correct and it is by design of RadGrid. Indeed whenever set_virtualItemCount function reset the pager Page command will be triggered which you can intercept on OnCommand client-side event and cancel it(using args.set_cancel(true)).

If you need to override this function however you can do this by placing the code below at the end of the page:
<script type="text/javascript">  
    Telerik.Web.UI.GridTableView.prototype.set_virtualItemCount = function(value)  
    {  
         //your custom code goes here  
    }  
</script> 


Regards,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Amjad
Top achievements
Rank 1
answered on 09 Dec 2012, 02:03 PM
Hi,
i have made a solution that i override the set_virtualitemcount method and removed the line that caused this problem since i have my own customized implementation on OnCommand event.

check it out
Telerik.Web.UI.GridTableView.prototype.set_virtualItemCount = function (value) {
if (this._virtualItemCount != value || value === 0) {
this._virtualItemCount = value;
if (value == 0 && (!this._dataSource || this._dataSource.length == 0)) {
this.set_currentPageIndex(0, true);
} else {
// this.set_currentPageIndex(0, false);
}
this._updatePager();
this._initializeVirtualScrollPaging();
}
}

nikolay please confirm
Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Answers by
Matthew
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Amjad
Top achievements
Rank 1
Share this question
or