Hello Mike,
You are right, sorry for missing that aspect.
You can consider a Dictionary that will be used to set the column titles in the Grid (by column ID), and provide the same id-title information to the custom component.
Regards,
Dimo
Progress Telerik
Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!
Hi Dimo,
Thanks for the suggestion, but I was under the impression that the GridState doesn't currently include the Column Title, and that would be needed to display to the end user for the custom component. I'm basing this assumption on this forum post: https://www.telerik.com/forums/separate-columnchooser-button so if this is no longer the case and I can access it via the grid state then I will go down that route. Otherwise, the workaround was to use reflection with a private property that you guys recommend against. Is there any other way to get that info outside of having to know the backend data?
Thanks,
Mike
Hello Mike,
25 votes is a good amount indeed, but it is still surpassed by quite a few other requests, including ones that are planned for our next release.
If you need a more convenient solution for a lot of Grids, please consider the following suggestion:
In this case the custom component will become reusable and self-sufficient. You may be able to remove the GetColumnVisibility() method from my example, because the custom component will be modifying the Grid state directly.
Regards,
Dimo
Progress Telerik
Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!
Is there any movement on this feature request? There is a fair amount of votes for this along with a few duplicates, and this was opened all the way back in 2022. Being able to have a single button in the toolbar instead of the column menu will free up a lot of real estate on the column headers so their titles aren't as truncated.
I understand there is a workaround suggestion, but while it is feasible for a few grids, I have hundreds of grids across my application and the level of effort of this non-generic workaround would be high. So, I'm hoping that this can be revisited.
Thanks.
@Hao - if you follow this item, you will receive email notifications when the item status changes. Currently there is no set development time frame yet.
In general, our Telerik Blazor releases follow a 6-week cycle.
In the meantime, here is just one of many possible implementations.
<TelerikGrid Data="@GridData"
TItem="@Product">
<GridToolBarTemplate>
<TelerikMultiSelect @ref="@MultiSelectRef"
Data="@GridColumns"
Value="@GridVisibleColumns"
ValueChanged="@( (List<string> newValues) => SetColumnVisibility(newValues) )"
ValueField="@nameof(ColumnDescriptor.Id)"
TextField="@nameof(ColumnDescriptor.Text)"
AutoClose="false"
Width="200px"
ClearButton="false"
Class="single-tag-mode">
</TelerikMultiSelect>
</GridToolBarTemplate>
<GridColumns>
<GridColumn Field="@nameof(Product.Name)"
Visible="@( GetColumnVisibility(nameof(Product.Name)) )" />
<GridColumn Field="@nameof(Product.Price)"
Visible="@( GetColumnVisibility(nameof(Product.Price)) )" />
<GridColumn Field="@nameof(Product.ReleaseDate)"
Visible="@( GetColumnVisibility(nameof(Product.ReleaseDate)) )" />
<GridColumn Field="@nameof(Product.Active)"
Visible="@( GetColumnVisibility(nameof(Product.Active)) )" />
</GridColumns>
</TelerikGrid>
<style>
/*
Single Tag Mode workaround:
https://feedback.telerik.com/blazor/1498325-add-a-tag-mode-summary-tag-mode
*/
.single-tag-mode .k-input-values {
float: left;
}
.single-tag-mode .k-input-values .k-chip {
display: none;
}
.single-tag-mode .k-input-values:before {
content: "Visible columns: @GridVisibleColumns.Count";
display: inline-block;
line-height: 1.8em;
padding: 0 7px;
vertical-align: bottom;
border: 1px solid rgba(0, 0, 0, 0.08);
border-radius: 4px;
background: #f5f5f5 linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.02));
}
</style>
@code {
List<Product> GridData { get; set; }
List<ColumnDescriptor> GridColumns { get; set; }
List<string> GridVisibleColumns { get; set; }
TelerikMultiSelect<ColumnDescriptor, string> MultiSelectRef { get; set; }
bool GetColumnVisibility(string id)
{
return GridVisibleColumns.Contains(id);
}
async Task SetColumnVisibility(List<string> newValues)
{
if (newValues.Count >= 1)
{
GridVisibleColumns = newValues;
}
}
protected override void OnInitialized()
{
GridData = new List<Product>();
var rnd = new Random();
for (int i = 1; i <= 3; i++)
{
GridData.Add(new Product()
{
Id = i,
Name = "Product " + i,
Price = (decimal)rnd.Next(1, 100),
ReleaseDate = DateTime.Now.AddDays(-rnd.Next(60, 1000)),
Active = i % 3 == 0
});
}
GridColumns = new List<ColumnDescriptor>();
GridColumns.Add(new ColumnDescriptor(nameof(Product.Name)));
GridColumns.Add(new ColumnDescriptor(nameof(Product.Price)));
GridColumns.Add(new ColumnDescriptor(nameof(Product.ReleaseDate)));
GridColumns.Add(new ColumnDescriptor(nameof(Product.Active)));
GridVisibleColumns = GridColumns.Select(x => x.Id).ToList();
}
public class ColumnDescriptor
{
public string Id { get; set; }
public string Text { get; set; }
public ColumnDescriptor(string id)
{
Id = Text = id;
}
}
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public DateTime ReleaseDate { get; set; }
public bool Active { get; set; }
}
}
Regards,
Dimo
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
Alternative 1 is fine for me.
One other thing you could think about is to make the "internal" lists of columns avalible by code. That way if some one wants to do the second alternative it is possible to implement it by them self. The problem now is that it is not possible for me to create a columns chooser since I can't find all information I need about all columns. I think when I tried that I was able to get it to for except that I was not able to get the title of the columns.
Hello everyone,
We have confirmed this to be a valid feature request. There are two ways to implement it - the ColumnChooser can be "Grid-aware" (1) or completely independent (2).
So far we assume (1), but let us know if anyone needs option (2).
Regards,
Dimo
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Having the column chooser embedded in the column is really confusing to users.
It needs to be at the end of the column titles, I think every column chooser I have seen
is done this way.