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

What is the sort expression for dynamic columns that come from a collection?

1 Answer 407 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 09 Feb 2018, 12:17 PM

Some columns in my grid are being added dynamically; their count and names come from a collection. All items in the grid have the same dynamic columns.
My data object looks like this:

class MyDataObject
{
    int ID;
    string Name;
    List<DynamicColumn> DynamicColumns;
}
 
/// <summary>
/// Holds a value for a single dynamic column cell
/// </summary>
class DynamicColumn
{
    int DynamicColumnDefinitionId; // points to an item in a global collection that defines the dynamic columns for the whole grid.
    int Value;
}

The resulting grid could have these columns:
| ID | Name | DynamicColummn1 | DynamicColummn2 | ... |

My question:
How can I sort by one of the dynamic columns? Can I use a sort expression like "DynamicColumn[i]" ?

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 14 Feb 2018, 07:59 AM
Hello Michael,

Generally, when you are utilizing the AutoGenerateColumns feature of the grid to generate the columns automatically you can use the OnColumnCreated event handler to modify their properties:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/columns/working-with-autogenerated-columns#customizing-auto-generated-columns

To apply actual sorting, you can use the SortExpressions collection of the MasterTableView:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/functionality/sorting/sort-expressions#sorting-programmatically

You can try doing that during the DataBinding event handler and remove the additional Rebind() at the end of the logic.

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or