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

[Solved] Dynamic column titles - can't get to work`

1 Answer 135 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Colin
Top achievements
Rank 1
Colin asked on 22 Aug 2010, 01:01 PM
Hi,

I am trying to do this:

.Columns(columns =>
{
    Action<int> addValueColumn =
        (i) => { columns.Bound(u => u.CompanyTechnologyRecoveries[i].Required).ClientTemplate("<input type='checkbox' disabled='disabled' name='CTR<#= CompanyTechnologyRecoveries[" + i + "].CompanyTechnologyRecoveryId #>' <#= CompanyTechnologyRecoveries[" + i + "].Required? \"checked='checked'\" : \"\" #> />").Width(140).Title("<#= CompanyTechnologyRecoveries[" + i + "].CompanyTechnologyName #>").Filterable(false); };
    columns.Bound(u => u.CriticalProcessName).Width(140).ReadOnly(true);
    columns.Bound(u => u.LocationName).Width(140).ReadOnly(true);
    columns.Bound(u => u.RecoveryPhaseName).Width(140).ReadOnly(true);            
    for (int i = 0; i < Model.FirstOrDefault().CompanyTechnologyRecoveries.Count; i++)
    {
        addValueColumn(i);
    }
    columns.Command(commands =>
    {
        commands.Edit();
        //commands.Delete();
    }).Width(180).Title("Commands");
})

However the title fails as it does not interpret the code.

Is there anyway to apply dynamic titles based upon the model data like this? Essentially the code above loops over each CompanyTechnologyRecovery object it finds, create a column for it but I also want it to create a dynamic title.

The data will always have the exact same number fo columns witht he exact same order of company technologies

Thanks for any help
Colin

1 Answer, 1 is accepted

Sort by
0
Mario van de Pol
Top achievements
Rank 1
answered on 14 Dec 2010, 03:08 PM
Action<int, string> addValueColumn =
               (i, title) => { columns.Bound(u => u.Column[i].val).Title(title); };
           for (int i = 0; i < Model.FirstOrDefault().Column.Count; i++)
           {
               addValueColumn(i, Model.FirstOrDefault().Column[i].title);
           }

This worked for me. Only loose my column values on sorting. Title remains intact. 
Tags
Grid
Asked by
Colin
Top achievements
Rank 1
Answers by
Mario van de Pol
Top achievements
Rank 1
Share this question
or