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

About ClientSettings.ClientEvents.OnCommand

3 Answers 132 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Zhao
Top achievements
Rank 1
Zhao asked on 17 Jul 2012, 02:54 AM
Hi team,

I got a problem when using the "ClientSettings.ClientEvents.OnCommand".
I want to catch the event when I click the pager number and change the pagesize by the dropdownlist. I looked up the document and found the using "ClientSettings.ClientEvents.OnCommand", so I wrote my code like this:

c#:

listGrid.ClientSettings.ClientEvents.OnCommand =

"RaiseCommand";

HTML:

 

 

function RaiseCommand(sender, eventArgs) {

 

 

var result = eventArgs.get_commandName();

 

 

switch (result) {

 

 

case "Page":

 

{

ShowCancelBtn();

 

break;

 

}

 

case "PageSize":

 

{

ShowCancelBtn();

 

break;

 

}

}

 

But I found that when I change the pagesize with the dropdownlist , the pager numbers  changes immediately before the grid data loading start!
For Example: when I use the pagesize "10" , the page number is "1,2,3" and total record count is 30 .when I change to pagesize"20", the page number changes immediately to "1,2" before the grid data began load.
In other word , the page numer is been calculate first and been shown, and then the grid data began load. I don't want it works like that. I thnk there must be something wrong with the "ClientSettings.ClientEvents.OnCommand", It causes the wrong order bettween page number shown and dataload. I need your help, team.




3 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 19 Jul 2012, 09:03 AM
Hello,

 This is more appropriate to be done on the server in the ItemCommand event - you can handle the page command there and access the DropDown as shown in this help topic.

Greetings,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Zhao
Top achievements
Rank 1
answered on 20 Jul 2012, 01:36 AM
hi Marin, 
I am sorry to say your solution did not work..  Can you understand my description? I just want to do something when I click the number of pager or select the  pagesize dropdown. I wonder how to trigger this event.  Looking forward to your reply.
0
Marin
Telerik team
answered on 24 Jul 2012, 02:09 PM
Hello,

 Yes, I understand your description and my suggestion is to use a server-side approach rather than client-side one. Here is a sample code how to handle the changing of the page on the server and change the page size accordingly:

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName.Contains("Page"))
        {
            RadGrid1.PageSize = 20;
            RadGrid1.Rebind();
        }
    }

Greetings,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Zhao
Top achievements
Rank 1
Answers by
Marin
Telerik team
Zhao
Top achievements
Rank 1
Share this question
or