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

Disable Reordering / Sorting for RadGrid Column

6 Answers 1132 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Siward Land
Top achievements
Rank 1
Siward Land asked on 14 Jan 2011, 04:59 PM
I have a radgrid with buttons on the first column that I don't want the user to sort or reorder.  I have sorting enabled and client-side reordering enabled.

How do I do this?

Thanks.

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Jan 2011, 12:18 PM
Hello,


You can disallow Sorting for particular column by setting the AllowSorting property of column to False.
 
Mark-up:
   <telerik:GridBoundColumn AllowSorting="false" SortExpression="ContactName" HeaderText="No sorting: Contact Name"
        DataField="ContactName" UniqueName="ContactName">
   </telerik:GridBoundColumn>


Now for disabling the reordering, attach the "OnColumnSwapping" client event and check for the column name, and cancel event if necessary.
function OnColumnSwapping(sender, args) {
    if (args.get_gridSourceColumn().get_uniqueName() == "ContactName") {
        alert("The column cannot moved");
        args.set_cancel(true);
    }
}



-Shinu.
0
Sony Telkar
Top achievements
Rank 1
answered on 19 Oct 2012, 09:33 AM
I want to do the same through code since my column are dynamic created in code.

Mark-up:
   <telerik:GridBoundColumn AllowSorting="false" SortExpression="ContactName" HeaderText="No sorting: Contact Name"
        DataField="ContactName" UniqueName="ContactName">
   </telerik:GridBoundColumn>

-Urgent
Please help
Sony
0
Shinu
Top achievements
Rank 2
answered on 19 Oct 2012, 09:45 AM
Hi,

Try disabling the sort as shown below.
C#:
GridBoundColumn boundColumn;
boundColumn = new GridBoundColumn();
RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField = "ContactName";
boundColumn.HeaderText = "ContactName";
boundColumn.UniqueName = "ContactName";
boundColumn.AllowSorting = false;

Thanks,
Shinu.
0
Sony Telkar
Top achievements
Rank 1
answered on 19 Oct 2012, 09:55 AM
Where should I call this code?
0
Jayesh Goyani
Top achievements
Rank 2
answered on 19 Oct 2012, 10:47 AM
Hello,

Please write below code in page_load,Page_PreRender , (Page_init)

Thanks,
Jayesh Goyani
0
Sony Telkar
Top achievements
Rank 1
answered on 19 Oct 2012, 10:50 AM
I found the other way of doing it which is working good.
under RadGrid1_ItemDataBound event

 

 

//disable sorting for 3 columns of string datatype

 

 

 

GridColumn gcView = RadGridView1.MasterTableView.GetColumn("View");

 

 

 

GridColumn gcQuestion = RadGridView1.MasterTableView.GetColumn("Question");

 

 

 

GridColumn gcAnswer = RadGridView1.MasterTableView.GetColumn("Answer");

 

 

 

GridBoundColumn gbcView = (GridBoundColumn)gcView;

 

 

 

GridBoundColumn gbcQuestion = (GridBoundColumn)gcQuestion;

 

 

 

GridBoundColumn gbcAnswer = (GridBoundColumn)gcAnswer;

 

gbcView.AllowSorting =

 

false;

 

gbcQuestion.AllowSorting =

 

false;

 

gbcAnswer.AllowSorting =

 

false;

Thanks a lot all of you who had for taking time and replying

 

Tags
Grid
Asked by
Siward Land
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Sony Telkar
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or