0
votes

I have to add custom column runtime on specific location to exiting telerik grid.

string[] customColumns = ds.Tables[2].Rows[0]["CustomColumns"].ToString().Split(',');
int startIndex = 7;
for (int i = 0; i < customColumns.Length; i++)
{
    GridBoundColumn NewColumn = new GridBoundColumn();
    tableGrid.MasterTableView.Columns.AddAt(startIndex, NewColumn);
    NewColumn.HeaderText = customColumns[i].Replace("[", "").Replace("]", "");
    NewColumn.DataField = customColumns[i].Replace("[", "").Replace("]", "");
    NewColumn.Visible = true;
    NewColumn.FilterControlWidth = Unit.Percentage(70);
    NewColumn.HeaderStyle.CssClass = "setHeader";
    NewColumn.HeaderStyle.Width = 130;
    NewColumn.AllowFiltering = true;
    NewColumn.OrderIndex = startIndex;
    startIndex++;
}

Using this block of code column added successfully at given location but when I used existing grid filter functionality then position of column is changed and even I can't see value in column.

enter image description here

1

1 Answers

0
votes

You will need to define an OrderIndex for the columns, and when adding a new one to the grid, you will know which OrderIndex to use. Check out the Reordering columns programmatically article for your reference.