Can we put IF condition in Grid column?

1 Answer 7230 Views
Grid
saroj
Top achievements
Rank 1
saroj asked on 11 Oct 2013, 02:31 AM
Hi Support,

I am trying to use FLEET_CUSTOM_FIELD_VALUE field for multiple data type while editing in grid,

so i tried using if condition for value coming through FLEET_CUSTOM_FIELD_DATATYPE  field in column but it's giving me error.

Any suggestion will be great.


public class CustomFieldValue
    {
        public int FLEET_ID { get; set; }
        public int FLEET_CUSTOM_FIELD_ID { get; set; }
        public string FLEET_CUSTOM_FIELD_VALUE { get; set; }
        public string FLEET_CUSTOM_FIELD_DESCRIPTION { get; set; }
        public string FLEET_CUSTOM_FIELD_DATATYPE { get; set; }
        public short FIELD_POSITION { get; set; }
        public string USER_UPDATE { get; set; }
    }

@(Html.Kendo().Grid<CustomFieldValue>()
            .Name("CustomFieldValue" + @ViewData["FLEET_ID"]) 
        .Sortable()
        .Pageable(paging =>
        {
            paging.Enabled(true);
            paging.Info(true);
            paging.PageSizes(true);
            paging.Numeric(true);
            paging.PreviousNext(true);
            paging.Refresh(true);
            paging.PageSizes(new int[5] { 5, 10, 15, 20, 25 });
        })
        .DataSource(dataSource => dataSource
            .Ajax()
                .Events(events =>
                {
                    events.RequestEnd("onCustomFieldValueRequestEnd");
                    events.Error("onCustomFieldValueListError"); 
                  
                })
                
            .PageSize(15)
            .Model(model =>
                {
                    model.Id(f => f.FLEET_CUSTOM_FIELD_ID);
                    model.Field(f => f.FLEET_CUSTOM_FIELD_DESCRIPTION).Editable(false);
                })

            .Read(read => read.Action("_CustomFieldValueList", "CustomFieldValueList", new { fleetId = ViewData["FLEET_ID"] }))
            .Update(update => update.Action("_CustomFieldValueListEdit", "CustomFieldValueList"))                  
        )
        .Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
        .Editable(editable => 
        {
            editable.Mode(GridEditMode.InLine);            
        })
        .Reorderable(reorder => reorder.Columns(true))
        .Filterable()
        .Columns(columns =>
        {
            columns.Bound(f => f.FLEET_CUSTOM_FIELD_ID).Title(" ").Hidden();
            columns.Bound(f => f.FLEET_CUSTOM_FIELD_DATATYPE).Title(" ").Hidden();
            columns.Bound(f => f.FLEET_CUSTOM_FIELD_DESCRIPTION).Title("Description");

            if ("#=FLEET_CUSTOM_FIELD_DATATYPE#" == "D")
            {
                columns.Bound(f => f.FLEET_CUSTOM_FIELD_VALUE).Title("Field value").EditorTemplateName("_Date").Width(250);
            }
            else
            {
                columns.Bound(f => f.FLEET_CUSTOM_FIELD_VALUE).Title("Field value").Width(250);
            }
            
            
            columns.Command(command =>
            {
                command.Edit();
            }).Width(250).Title("Commands").HeaderHtmlAttributes(new { @style = "text-align:left; text-decoration:Underline;" });
        })
        .Events(e=>e.Edit("edit"))
        
    ) 

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 11 Oct 2013, 11:08 AM
Hello Saroj,

IF statements, which depend on datasource values can be used only inside column templates.

http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/faq#how-do-i-have-conditional-logic-in-a-column-client-template?

Moreover, IF statements, which depend on values that are retrieved and available only client-side as a result of Ajax binding cannot be used in a source code, which is evaluated on the server.

Regards,
Dimo
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
saroj
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or