Is there anyway to enable sorting and filtering on a column with a binding converter ...
like so
<telerikGridView:RadGridView x:Name="ItemListGrid" Grid.Row="1" AutoGenerateColumns="False" IsReadOnly="True" Margin="0,0,0,0" ItemsSource="{Binding Data, ElementName=ddsItemList}" CanUserInsertRows="False" > |
<telerikGridView:RadGridView.Columns> |
<telerikGridView:GridViewDataColumn Header="Manufacturer" DataMemberBinding="{Binding ManfMaster.NameManf}" Width="Auto" /> |
<telerikGridView:GridViewDataColumn Header="PartNumber" DataMemberBinding="{Binding ManfNo}" Width="Auto" /> |
<telerikGridView:GridViewDataColumn Header="Description" DataMemberBinding="{Binding ItemMaster.ZDesc}" Width="Auto" TextAlignment="Left"/> |
<telerikGridView:GridViewDataColumn Header="Min Level" DataMemberBinding="{Binding . ,Converter={StaticResource ItemListMinLevel} }" Width="Auto" TextAlignment="Right"/> |
<telerikGridView:GridViewDataColumn Header="Max Level" DataMemberBinding="{Binding . ,Converter={StaticResource ItemListMaxLevel} }" Width="Auto" TextAlignment="Right"/> |
<telerikGridView:GridViewDataColumn Header="MSD Level" DataMemberBinding="{Binding MsdLevelMaster,Converter={StaticResource ItemListMSDLevel} }" Width="Auto" TextAlignment="Left"/> |
</telerikGridView:RadGridView.Columns> |
</telerikGridView:RadGridView> |
Unfortunately i am using the ria domain data source and the pager .
So as far as i know i cannot wrap the objects being returned by the domain data source
Unless I suppose i do it on the server side in the query
The converted columns are used to expose nested object propertys with special needs (lol).
Any help would be appreciated.
thanks
dco
17 Answers, 1 is accepted
Converters are only for UI purposes and since the grid will perform these operations on the data-source level this cannot be achieved. We have plans however to provide calculated column (in Q1 2010) with support for grouping, filtering, sorting, etc. similar to our ASP.NET grid.
Sincerely yours,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Was hoping for something super creative or super secret (lol).
thanks anyway vlad
dco
As Vlad said, the data engine of RadGridView can not perform operations on UI objects such as binding converters.
What can be done here is to expose the converted value via property of your business object and use the SortMember path of the column to redirect sorting logic to the new property ( containing the converted value )
All the best,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I would be happy to provide you with a sample project but first can you please give me more details about your requirements so that my example is as close as possible to your case.
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I am using ria service EFW, on the page
private ObservableCollection<PwrSmartService.Web.Computer> computeritemsSource;
public PagedCollectionView result = null;
For load data:
var computerQuery = this.myDomainContext.GetComputersByGroupIDQuery(G.GroupID);
var loadOperation = this.myDomainContextLoad(computerQuery, LoadBehavior.RefreshCurrent, true);
loadOperation.Completed += (sender1, args) =>
{
if (loadOperation.HasError)
ErrorHandler.HandleOperationError("Err", loadOperation);
else
{
if (radGridViewComputer != null)
{
computeritemsSource =
new ObservableCollection<PwrSmartService.Web.Computer>(loadOperation.Entities);
result =
new PagedCollectionView(computeritemsSource);
result.PageSize = GridPageSize;
radGridViewComputer.ItemsSource = result;
radGridViewComputer.SelectedItems.Clear();
RadDataPagerComputer.Source = result;
}
}
so on my Radgridview I need to display some column by passing computer
Here is my converter code
public class ComputerActivePwrSchemeConverter : IValueConverter
{
#region
IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Computer c = value as Computer;
String sRet = "";
if (c != null)
{
foreach (vw_ComputerActivePowerConfigs vwActive in myContext.vw_ComputerActivePowerConfigs)
{
if (vwActive.ComputerID == c.ComputerID)
{
sRet = vwActive.SchemeName;
return sRet;
}
return sRet;
}
else return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
on xmal
<telerikGridView:GridViewDataColumn x:Name="ActiveSchemeColumn" DataMemberBinding="{Binding Converter={StaticResource ComputerActivePwrSchemeConverter}}" Header="Active Scheme" Width="Auto"/>
}
This column doest not has sort or filter now.
Thank you for your help.
Since in your case modifying the business object is limited by RIA , I may suggest a slightly different approach .
It is demonstrated in the sample attached.
On a click on the column header RadGridView would sort either by the original value , or by the converted value depending on the user selection.
This is achieved by handling the RadGridView.sorting event and performing own sorting logic when the user clicks on column headers.
Regards,
Pavel Pavlov
the Telerik team
I was looking for the calculated column... Has it been added?
In my RIA WCF services I added a calculated field to one of my entity like that:
using
System.Runtime.Serialization;
namespace
AWeb
{
public
partial
class
ProgramDetail
{
[DataMember]
public
string
FormattedShowName
{
get
{
if
(
string
.IsNullOrWhiteSpace(
this
.ShowName))
{
return
this
.Title;
}
else
{
return
string
.Format(
"{0} S{1:00}E{2:00}"
,
this
.ShowName,
this
.Season,
this
.Episode);
}
}
set
{ }
}
}
}
When I try to use that column in a group using drag and drop, I get the following error:
---------------------------
Program List Load Error
---------------------------
System.ServiceModel.DomainServices.Client.DomainOperationException: Load operation failed for query
'GetProgramDetailByTypes'
. The specified type member
'FormattedShowName'
is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
---------------------------
OK
---------------------------
I understand the error, the real entity used in the linq sort query does not find the property, but so the operation still works, the rows are correctly grouped by that column I guess there might be something to do so that I don't get the exception.
And that solution might be a special calculated column that handles such cases... Has this been added?
Also, I tryed to use the SortPathMember property to redirect the sort operation but this has no effect on my grouping problem.
Any hints on how to proceed except handling the sort by myself ?
Thanks a lot for your help,
John.
Let's say you have an entity called "User", and that entity has 2 properties, "Name", "BirthDate", and you want to have a property called "Age".
Just create a new Class like:
[Serializable()]
public
class
UserWithMetaData
{
[Key]
public
String Name {
get
;
set
; }
public
DateTime BirthDate {
get
;
set
; }
public
double
Age {
get
;
set
; }
}
In your DomainService class, just add something like:
[Query(IsDefault =
true
)]
public
List<UserWithMetaData> GetUsersWithMetaData()
{
List<UserWithMetaData> Result =
new
List<UserWithMetaData>();
foreach
(var e
in
GetUsers().OrderBy(e => e.Name))
{
Result.Add(
new
UserWithMetaData()
{
Name = e.Name,
BirthDate = e.BirthDate,
Age = DateTime.Now.Subtract(e.BirthDate).TotalDays / 365
});
}
return
Result;
}
Good Luck!
Thanks for jumping in...
You are right this can be a workaround...
In fact thanks for suggesting it. Without real solution I might end using this.
Just, I find this is too much of an overhead. To achieave the same result I need an extra class and I need to copy tha data from one list to another when I could just live with my solution if it would integrate in the grid with something like a Calculated column.
Also I must have missed somthing as using a partial class seems to be the recomended way of extending an entity used in RIA WCF Services... I may prove wrong...
Any other hints?
Thanks anyway...
John.
Did anything ever happen with this? I agree this problem can be solved with a local view model, but I would rather the grid took care of it. That would allow me to keep using the service generated objects without having to build a mostly identical middle man.
At the very least, the filter could run the value through the convertback function of the converter before it performed the filtering.
Grouping and sorting is already supported in our expression column and we will add filtering support with our upcoming Q1 2012 (middle of February).
Regards,Vlad
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Based on your previous post in this thread, dated Jan 6, 2012:
Is sorting and filtering of converter based columns supported yet in the latest release of Silverlight 5 RadControls?
I ask this because, using the built-in filter dialog, we are only able to get the Contains option to filter converter based columns.
Thanks...Bob Baldwin
Trabon Solutions
Regards,
Vlad
the Telerik team"
Did this ever make it into the Silverlight Controls for Silverlight 5?
Yes, we added filtering support with GridViewExpressionColumn. You can check the Calculated Column demo on how the sorting, grouping and filtering functionality is supported.
Regards,
Didie
Telerik