Telerik Grid Multiline Cell (MVC3)

Using the grid Telerik MVC3, C #,. Net 2010;

I have a grid in my razor mode:

@(Html.Telerik().Grid<ProductListItem>() .Name("Grid") .Columns(columns => { columns.Bound(o => o.Current.Name).Sortable(true).Filterable(false).Width(150); columns.Bound(o => o.Categories).Sortable(true).Filterable(false).Width(200); //other column bindings... }) .DataBinding(dataBinding => dataBinding.Ajax().Select(Model.GridAjaxRequestAction.ActionName, Model.GridAjaxRequestAction.ControllerName)) .Pageable(settings => settings.Total(Model.TotalRow)) .EnableCustomBinding(true) .Sortable() .Filterable() 

What I want to do is set the grid category column as multi-row.

There can be many categories for a product, so the category cells in the grid should be similar;

 Category0 Category1 Category2 

I tried to join category values ​​using System.NewLine and
and assign these values ​​to the ProductListItem.Categories property. He does not change. The text is still one line.

Thanks in advance.

+6
source share
2 answers

Thanks @nekno. I came up with this solution in my case. Sorry for not responding for some time.

in the field of view of the model:

this.Categories = String.Join("<br>", entity.Categories.Select(o => o.Current.Name));

in sight: columns.Bound (o => o.Categories) .ClientTemplate ("<# = Categories #>")

+4
source

If it’s convenient for you when you tried to connect using NewLine , try "<br />" instead of System.NewLine .

Otherwise, what is the data type of your ProductListItem.Categories property? If it's a List<String> or some other IEnumerable , you can use a template column instead of a linked column. You use item to reference the current ProductListItem in the template:

 @(Html.Telerik().Grid<ProductListItem>() .Name("Grid") .Columns(columns => { columns.Bound(o => o.Current.Name).Sortable(true).Filterable(false).Width(150); columns.Template( @<text> @String.Join("<br />", item.Categories) </text>) .Sortable(true).Filterable(false).Width(200); //other column bindings... }) .DataBinding(dataBinding => dataBinding.Ajax().Select(Model.GridAjaxRequestAction.ActionName, Model.GridAjaxRequestAction.ControllerName)) .Pageable(settings => settings.Total(Model.TotalRow)) .EnableCustomBinding(true) .Sortable() .Filterable() 

Another option would be to create a table in the template column and leave ProductListItem.Categories as a List , for example, this.Categories = entity.Categories.Select(o => o.Current.Name).ToList();

 @(Html.Telerik().Grid<ProductListItem>() .Name("Grid") .Columns(columns => { columns.Bound(o => o.Current.Name).Sortable(true).Filterable(false).Width(150); columns.Template( @<text> <table border=0> @foreach(var category in item.Categories){ <tr><td>@category</td></tr> } </table> </text>) .Sortable(true).Filterable(false).Width(200); //other column bindings... }) .DataBinding(dataBinding => dataBinding.Ajax().Select(Model.GridAjaxRequestAction.ActionName, Model.GridAjaxRequestAction.ControllerName)) .Pageable(settings => settings.Total(Model.TotalRow)) .EnableCustomBinding(true) .Sortable() .Filterable() 
+1
source

Source: https://habr.com/ru/post/894381/


All Articles