Hi,
I have used a dynamically generated RadGrid for my application.
I would like to use the following functions:
1) Freeze header
2) Freeze columns
3) Resize one of the column
I know there's an article saying that resizing the column does not work with freezing header, so if we are to only use the freeze header and columns there are still some issues
here's the issues and settings I used:
- Freeze header only, no freezing columns
The grid has some alignment issue when scroll to the end, the header and content line is not aligned.
Pls see freezeheaderalignment.jpg
- Freeze header and column (must use layout = auto to make it show)
The last column disappear when using both freeze header and column and somehow the header height become very big and is it because of my fixed height, now i have 3 vertical scroll bars :(
Pls see freezeheaderncolumn.jpg
Also I noticed that I have to specify the width of each column otherwise the column will shrink, is there any auto-size property to automatically resize the column width as per content?
Here's my code:
I have used a dynamically generated RadGrid for my application.
I would like to use the following functions:
1) Freeze header
2) Freeze columns
3) Resize one of the column
I know there's an article saying that resizing the column does not work with freezing header, so if we are to only use the freeze header and columns there are still some issues
here's the issues and settings I used:
- Freeze header only, no freezing columns
The grid has some alignment issue when scroll to the end, the header and content line is not aligned.
Pls see freezeheaderalignment.jpg
- Freeze header and column (must use layout = auto to make it show)
The last column disappear when using both freeze header and column and somehow the header height become very big and is it because of my fixed height, now i have 3 vertical scroll bars :(
Pls see freezeheaderncolumn.jpg
Also I noticed that I have to specify the width of each column otherwise the column will shrink, is there any auto-size property to automatically resize the column width as per content?
Here's my code:
RadGrid1 =
new
RadGrid();
RadGrid1.ID =
"RadGrid1"
;
RadGrid1.Height = Unit.Pixel(535);
int
intDefaultPercentage = 99;
bool
isFixed =
false
;
if
(!ConfigHelper.OPDashboardLayout.Equals(
""
))
{
if
(ConfigHelper.OPDashboardLayout.ToUpper().Equals(
"Fixed"
))
isFixed =
true
;
RadGrid1.MasterTableView.TableLayout = (GridTableLayout)Enum.Parse(
typeof
(GridTableLayout), ConfigHelper.OPDashboardLayout);
}
RadGrid1.AutoGenerateColumns =
false
;
RadGrid1.ClientSettings.Scrolling.AllowScroll =
true
;
RadGrid1.ItemDataBound +=
new
GridItemEventHandler(RadGrid1_ItemDataBound);
RadGrid1.PreRender +=
new
EventHandler(RadGrid1_PreRender);
RadGrid1.ColumnCreated +=
new
GridColumnCreatedEventHandler(RadGrid1_ColumnCreated);
RadGrid1.DetailTableDataBind +=
new
GridDetailTableDataBindEventHandler(RadGrid1_DetailTableDataBind);
RadGrid1.NeedDataSource +=
new
GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
RadGrid1.ExcelExportCellFormatting +=
new
OnExcelExportCellFormattingEventHandler(RadGrid1_ExcelExportCellFormatting);
RadGrid1.MasterTableView.Name =
"Master"
;
RadGrid1.MasterTableView.DataKeyNames =
new
string
[] {
"KIID"
};
RadGrid1.MasterTableView.GroupLoadMode = GridGroupLoadMode.Client;
RadGrid1.MasterTableView.Width = Unit.Percentage(intDefaultPercentage);
RadGrid1.MasterTableView.HeaderStyle.Wrap =
true
;
if
(isFixed)
{
RadGrid1.CssClass =
"AutoShrink"
;
RadGrid1.MasterTableView.CssClass =
"AutoShrink"
;
}
//RadGrid1.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client;
GridRelationFields relationFields =
new
GridRelationFields();
relationFields.MasterKeyField =
"KIID"
;
relationFields.DetailKeyField =
"KIID"
;
RadGrid1.MasterTableView.ParentTableRelation.Add(relationFields);
RadGrid1.ClientSettings.AllowGroupExpandCollapse =
true
;
GridGroupByExpression groupExpression =
new
GridGroupByExpression();
GridGroupByField selectField =
new
GridGroupByField();
//selectField.FieldAlias = "Vertical";
selectField.HeaderText =
" "
;
selectField.FieldName =
"VerticalDisplayName"
;
selectField.HeaderValueSeparator =
""
;
GridGroupByField groupField =
new
GridGroupByField();
groupField.FieldName =
"VerticalDisplaySequence"
;
groupExpression.SelectFields.Add(selectField);
groupExpression.GroupByFields.Add(groupField);
RadGrid1.MasterTableView.GroupByExpressions.Add(groupExpression);
#region MasterView
GridBoundColumn processColumn =
new
GridBoundColumn();
processColumn.UniqueName =
"ProcessDescription"
;
processColumn.DataField =
"ProcessDescription"
;
processColumn.HeaderText =
"Process Description"
+ ApplicationConstant.LINEBREAK +
"Key Indicator Code"
;
if
(ConfigHelper.OPDashboardWidthProcess > 0)
processColumn.HeaderStyle.Width = Unit.Pixel(ConfigHelper.OPDashboardWidthProcess);
if
(ConfigHelper.OPDashboardResizeRemarks)
processColumn.Resizable =
false
;
RadGrid1.MasterTableView.Columns.Add(processColumn);
GridBoundColumn KIColumn =
new
GridBoundColumn();
KIColumn.UniqueName =
"KI"
;
KIColumn.DataField =
"KIDescription"
;
KIColumn.HeaderText =
"Key Indicator Description"
;
if
(ConfigHelper.OPDashboardWidthKI > 0)
KIColumn.HeaderStyle.Width = Unit.Pixel(ConfigHelper.OPDashboardWidthKI);
if
(ConfigHelper.OPDashboardResizeRemarks)
KIColumn.Resizable =
false
;
RadGrid1.MasterTableView.Columns.Add(KIColumn);
GridBoundColumn KIColumnHidden =
new
GridBoundColumn();
KIColumnHidden.UniqueName =
"KIOriginal"
;
KIColumnHidden.DataField =
"KIDescription"
;
if
(ConfigHelper.OPDashboardWidthKI > 0)
KIColumn.HeaderStyle.Width = Unit.Pixel(ConfigHelper.OPDashboardWidthKI);
KIColumnHidden.Visible =
false
;
RadGrid1.MasterTableView.Columns.Add(KIColumnHidden);
GridBoundColumn remarksColumn =
new
GridBoundColumn();
remarksColumn.UniqueName =
"Remarks"
;
remarksColumn.DataField =
"Remarks"
;
remarksColumn.HeaderText =
"Remarks"
;
if
(ConfigHelper.OPDashboardWidthRemarks > 0)
remarksColumn.HeaderStyle.Width = Unit.Pixel(ConfigHelper.OPDashboardWidthRemarks);
RadGrid1.MasterTableView.Columns.Add(remarksColumn);
GridBoundColumn remarksColumnHidden =
new
GridBoundColumn();
remarksColumnHidden.UniqueName =
"RemarksOriginal"
;
remarksColumnHidden.DataField =
"Remarks"
;
remarksColumnHidden.Visible =
false
;
if
(ConfigHelper.OPDashboardWidthRemarks > 0)
remarksColumn.HeaderStyle.Width = Unit.Pixel(ConfigHelper.OPDashboardWidthRemarks);
RadGrid1.MasterTableView.Columns.Add(remarksColumnHidden);
for
(
int
i = 1; i <=
int
.Parse(ConfigHelper.OPDashboardMaxPeriodRange); i++)
{
GridTemplateColumn masterPeriodColumn =
new
GridTemplateColumn();
masterPeriodColumn.UniqueName = PERIODCOLUMNPREFIX + i.ToString();
masterPeriodColumn.ItemTemplate =
new
KRIPeriodTemplateColumn(i.ToString());
masterPeriodColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
if
(ConfigHelper.OPDashboardWidthMonths > 0)
masterPeriodColumn.HeaderStyle.Width = Unit.Pixel(ConfigHelper.OPDashboardWidthMonths);
masterPeriodColumn.HeaderStyle.Wrap =
true
;
if
(ConfigHelper.OPDashboardResizeRemarks)
masterPeriodColumn.Resizable =
false
;
RadGrid1.MasterTableView.Columns.Add(masterPeriodColumn);
}
GridTemplateColumn thresholdColumn =
new
GridTemplateColumn();
thresholdColumn.UniqueName =
"ThresholdColumn"
;
thresholdColumn.ItemTemplate =
new
KRIThresholdTemplateColumn();
thresholdColumn.Visible = blnShowThreshold;
if
(ConfigHelper.OPDashboardWidthThreshold > 0)
thresholdColumn.HeaderStyle.Width = Unit.Pixel(ConfigHelper.OPDashboardWidthThreshold);
//thresholdColumn.HeaderText = "Threshold";
thresholdColumn.HeaderText =
"Threshold"
+ ApplicationConstant.LINEBREAK +
"(in $)"
;
thresholdColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
thresholdColumn.HeaderStyle.Wrap =
true
;
if
(ConfigHelper.OPDashboardResizeRemarks)
thresholdColumn.Resizable =
false
;
RadGrid1.MasterTableView.Columns.Add(thresholdColumn);
#endregion
#region DetailView
GridTableView tableView1 =
new
GridTableView();
tableView1.Name =
"Detail"
;
tableView1.DataKeyNames =
new
string
[] {
"KIID"
,
"AssetTypeCode"
};
tableView1.Width = Unit.Percentage(intDefaultPercentage);
tableView1.HeaderStyle.Wrap =
true
;
RadGrid1.MasterTableView.DetailTables.Add(tableView1);
GridBoundColumn assetDescriptionColumn =
new
GridBoundColumn();
assetDescriptionColumn.UniqueName =
"AssetTypeDescription"
;
assetDescriptionColumn.DataField =
"AssetTypeDescription"
;
assetDescriptionColumn.HeaderText =
"Description"
;
if
(ConfigHelper.OPDashboardWidthProcess > 0 || ConfigHelper.OPDashboardWidthKI > 0)
assetDescriptionColumn.HeaderStyle.Width = Unit.Pixel(ConfigHelper.OPDashboardWidthProcess + ConfigHelper.OPDashboardWidthKI);
tableView1.Columns.Add(assetDescriptionColumn);
GridBoundColumn assetTypeColumn =
new
GridBoundColumn();
assetTypeColumn.UniqueName =
"AssetTypeCode"
;
assetTypeColumn.DataField =
"AssetTypeCode"
;
assetTypeColumn.HeaderText =
"Asset Type"
;
if
(ConfigHelper.OPDashboardWidthRemarks > 0)
assetTypeColumn.HeaderStyle.Width = Unit.Pixel(ConfigHelper.OPDashboardWidthRemarks);
tableView1.Columns.Add(assetTypeColumn);
//Pad column to align with Remarks
GridHyperLinkColumn paddingRemarksColumn =
new
GridHyperLinkColumn();
paddingRemarksColumn.UniqueName =
"PaddingRemarksColumn"
;
paddingRemarksColumn.Text =
""
;
paddingRemarksColumn.HeaderText =
""
;
tableView1.Columns.Add(paddingRemarksColumn);
for
(
int
i = 1; i <=
int
.Parse(ConfigHelper.OPDashboardMaxPeriodRange); i++)
{
GridTemplateColumn detailPeriodColumn =
new
GridTemplateColumn();
detailPeriodColumn.UniqueName = PERIODCOLUMNPREFIX + i.ToString();
detailPeriodColumn.ItemTemplate =
new
KRIPeriodTemplateColumn(i.ToString());
detailPeriodColumn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
if
(ConfigHelper.OPDashboardWidthMonths > 0)
detailPeriodColumn.HeaderStyle.Width = Unit.Pixel(ConfigHelper.OPDashboardWidthMonths);
tableView1.Columns.Add(detailPeriodColumn);
}
#endregion
#region Freeze Header
RadGrid1.ClientSettings.Scrolling.UseStaticHeaders = ConfigHelper.OPDashboardFreezeHeader;
#endregion
#region Freeze Column
if
(ConfigHelper.OPDashboardFrozenColumns > 0)
{
RadGrid1.ClientSettings.Scrolling.FrozenColumnsCount = ConfigHelper.OPDashboardFrozenColumns;
RadGrid1.ClientSettings.Scrolling.SaveScrollPosition =
true
;
}
#endregion
#region Resizing
if
(ConfigHelper.OPDashboardResize)
{
RadGrid1.ClientSettings.Resizing.AllowColumnResize =
true
;
RadGrid1.ClientSettings.Resizing.ResizeGridOnColumnResize =
false
;
RadGrid1.ClientSettings.Resizing.EnableRealTimeResize =
true
;
}
#endregion