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

[Solved] Column sort without postback for dynamically created grid question

3 Answers 240 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gary B.
Top achievements
Rank 1
Gary B. asked on 07 Jul 2009, 03:26 PM
I am creating a grid on the back end and adding it to a RadDock, but I want the columns to be sortable on the client side.
It looks like it is working here for a hard-coded grid
http://demos.telerik.com/aspnet-ajax/grid/examples/client/clientsideevents/defaultcs.aspx
However, whenever I click on my column header it does a postback (which doesn't work for me).
I am just binding to a static DataTable and the grid is non-editable.
RadGrid grid = new RadGrid(); 
grid.ID = "RadGrid1"
grid.AllowSorting = true
grid.AllowPaging = true
grid.PageSize = 5; 
grid.ClientSettings.ReorderColumnsOnClient = true
grid.ClientSettings.EnableRowHoverStyle = true
grid.ClientSettings.ClientEvents.OnColumnClick = "ColumnClick"
grid.ClientSettings.ClientEvents.OnColumnClick = "ColumnDblClick"
grid.DataSource = srts.DefaultView; // srts is the DataTable 
grid.DataBind(); 
dock.ContentContainer.Controls.Add(grid); 
The on column click and double click events do work, but don't seem to do any sorting, I am using the javascript from the link above.
Also, I am setting this up on load, in case that matters (it is dynamic because it is based on what is Posted to the page).
Is there some property I need to add or other control involved?
Thanks


3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 08 Jul 2009, 06:25 AM
Hi Gary,

In the above demo they are using RadAjaxManager to ajaxify the Grid. But I have found an interesting video which explains Client side sorting. Go through it and see whether it helps.
RadGrid for ASP.NET AJAX - Client-Side Sorting

Shinu.
0
Gary B.
Top achievements
Rank 1
answered on 09 Jul 2009, 08:04 PM
Ok, I thought that was going to help, but the first problem I ran into is that "The name 'RadGrid1' does not exist in the current context" is thrown due to line
var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView(); 
My grid.ID is "RadGrid1" but I think the problem is that I am creating it in the code behind so the js isn't finding it. Although, I am creating the grid on Page_Load, so it should exist when the js is loaded, right?
I also tried
var tableView = $find("<%= grid.ClientID %>").get_masterTableView(); 
 
since the RadGrid codebehind name is grid, but that had the same issue. I am not familiar with classic ASP (which is what the <%=...%> looks like), but that appears to be getting handled before the Page_Load, is that right?

To clarify, my codebehind to create the grid now is
RadGrid grid = new RadGrid(); 
grid.ID = "RadGrid1"
grid.EnableViewState = false
grid.AllowSorting = true
grid.ClientSettings.ReorderColumnsOnClient = true
grid.DataSource = srts.DefaultView; 
grid.DataBind(); 
dock.ContentContainer.Controls.Add(grid); 

0
Sebastian
Telerik team
answered on 14 Jul 2009, 11:28 AM
Hello Gary,

How to get reference to the RadGrid client object when it resides in RadDock or a template of another control you can see from the sample projects in the code library threads linked below:

http://www.telerik.com/community/code-library/aspnet-ajax/grid/accessing-server-controls-in-a-grid-template-on-the-client.aspx (applicable for nested RadGrid as well)

http://www.telerik.com/community/code-library/aspnet-ajax/general/find-radgrid-client-side-if-it-is-nested-in-a-template-of-another-control.aspx

Kind regards,
Sebastian
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.
Tags
Grid
Asked by
Gary B.
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Gary B.
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or