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

[Solved] How can I sort RadGrid clientside on specific column.

3 Answers 254 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Harshit
Top achievements
Rank 1
Harshit asked on 13 Oct 2011, 03:28 PM
I have a radgrid on page and i bind data on serverside. Bydefault sorting is set to false on grid. But on click of a checkbox on a container page, I want to sort grid data on specific column.  for example below, on click of a checkbox I want to sort my data as Active customer on top or Inactive customers on top.  How would I do that on clientside.? Can I enable sorting on individual column only?

ID Name Total Orders Active
1 Customer 1 9 TRUE
2 Customer 2 11 FALSE
3 Customer 3 2 FALSE
4 Customer 4 20 TRUE
5 Customer 5 31 TRUE

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Oct 2011, 03:40 PM
Hello Harshit,

You can enable client side sorting  using the following approach.
CS:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)
    {
        foreach (GridHeaderItem header in RadGrid1.MasterTableView.GetItems(GridItemType.Header))
         {
             header[col.UniqueName].Attributes.Add("OnClick", "return SortColumn('"+ col.UniqueName+ "');");
         }
     }
}
JS:
<script type="text/javascript">
 function SortColumn(ColumnName)
 {
    var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
    masterTable.sort(ColumnName);
}
</script>

Thanks,
Shinu.
0
Prathibarani
Top achievements
Rank 1
answered on 03 Apr 2013, 08:13 PM
Hi,
I used your code and clicked on one of the column headers to sort. Since nothing is implemented in sort event and need datasource events, nothing is displayed on page. I am binding grid in page load event and not postback and when ever I require binding. Please let me know how to do it.

Thanks,
Prathiba
0
Eyup
Telerik team
answered on 08 Apr 2013, 12:17 PM
Hello Prathiba,

Please note that using DataBind() is not recommended. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, grouping, Paging, Sorting, Filtering require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Advanced Data Binding

Hope this helps.

Kind regards,
Eyup
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
Harshit
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Prathibarani
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or