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

Grid Header Template with ITemplate

1 Answer 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 29 Jan 2009, 10:04 PM
I've created a class from the ITempalte and I was wondering if there was an easy way to hook up grid sorting to the temaplate

The template displays just fine, but of course there is no sorting. Now that I think about it is there a way I could hook up column resize, and reorder?

 

var col = new GridTemplateColumn

 

{

ItemTemplate =

new DetailTemplate(),

 

UniqueName =

"Detail",

 

};

col.HeaderTemplate =

new DetailHeaderTemplate();

 

RadGrid1.Columns.Add(col);

PlaceHolder1.Controls.Add(RadGrid1);



public

 

class DetailHeaderTemplate : ITemplate

 

{

 

public void InstantiateIn(Control container)

 

{

 

var table = new Table { CellPadding = 0, CellSpacing = 0 };

 

table.Style.Add(

"width", "100%");

 

table.Style.Add(

"border", "1px");

 

 

var row = new TableRow();

 

 

var cell = new TableCell();

 

cell.Style.Add(

"width","33%");

 

cell.Text =

"Desc";

 

row.Cells.Add(cell);

cell =

new TableCell();

 

cell.Style.Add(

"width", "33%");

 

cell.Text =

"Dist #";

 

row.Cells.Add(cell);

cell =

new TableCell();

 

cell.Style.Add(

"width", "33%");

 

cell.Text =

"Price";

 

row.Cells.Add(cell);

table.Rows.Add(row);

container.Controls.Add(table);

}

}


1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 02 Feb 2009, 04:15 PM
Hi Craig,

You can implement filtering and sorting for sub-columns in your template columns as illustrates in these examples:

http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/columntypes/defaultcs.aspx (see the last column in the grid and the buttons inside its header template)

http://www.telerik.com/community/code-library/aspnet-ajax/grid/individual-filtering-and-sorting-for-sub-columns-in-template-column.aspx

The difference is that you will need to generate the controls programmatically instead of declaratively. Column resize and reorder can be handled for the entire template column (not for nested sub-columns in it) in the same manner as with other grid controls.

Best regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Craig
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or