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

binding converters and sorting/filtering

17 Answers 498 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
David Ocasio asked on 16 Nov 2009, 12:58 PM

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

Sort by
0
Accepted
Vlad
Telerik team
answered on 16 Nov 2009, 01:03 PM
Hello,

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.
0
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 16 Nov 2009, 01:29 PM
Thought as much.
Was hoping for something super creative or super secret (lol). 

thanks anyway vlad
dco
0
Jane
Top achievements
Rank 1
answered on 04 Jun 2010, 09:31 PM
Any update on the binding converter column sort/filtering?
0
Pavel Pavlov
Telerik team
answered on 08 Jun 2010, 02:02 PM
Hi Jane,

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.
0
Jane
Top achievements
Rank 1
answered on 08 Jun 2010, 04:05 PM
Pavel, Thank you for your reply. I am new to the silverlight. Can you send me a project to demo it?
0
Maya
Telerik team
answered on 10 Jun 2010, 07:44 PM
Hi Jane,

 
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.

Regards,
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.
0
Jane
Top achievements
Rank 1
answered on 11 Jun 2010, 07:36 PM
Pavel,
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.

0
Pavel Pavlov
Telerik team
answered on 17 Jun 2010, 04:33 PM
Hi Jane,
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
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
0
Jonx
Top achievements
Rank 2
answered on 29 Aug 2010, 05:19 PM
Hello Vlad,
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.


 

0
Nick
Top achievements
Rank 2
answered on 29 Aug 2010, 08:33 PM
Why don't you just add an entry to the DomainService class on the .Web project end?

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!
0
Jonx
Top achievements
Rank 2
answered on 29 Aug 2010, 09:56 PM
Hello nick,
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. 
0
Joel
Top achievements
Rank 1
answered on 05 Jan 2012, 04:47 PM
"We have plans however to provide calculated column (in Q1 2010) with support for grouping, filtering, sorting, etc. similar to our ASP.NET grid."

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.
0
Joel
Top achievements
Rank 1
answered on 06 Jan 2012, 03:44 PM
I think this is called a calculated column for the other platforms, but it ended up being called the expression column for silverlight.  It's there now, but it doesn't natively support any of the filtering that comes with the regular columns, so beware.
0
Vlad
Telerik team
answered on 06 Jan 2012, 03:53 PM
Hi,

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 >>

0
Bob
Top achievements
Rank 1
answered on 12 Sep 2012, 08:17 PM
Hi Vlad,

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
0
Uncle Steve
Top achievements
Rank 1
answered on 29 May 2014, 03:49 PM
"Hi, 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"

Did this ever make it into the Silverlight Controls for Silverlight 5?
0
Dimitrina
Telerik team
answered on 02 Jun 2014, 08:12 AM
Hello,

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
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Vlad
Telerik team
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
Jane
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Maya
Telerik team
Jonx
Top achievements
Rank 2
Nick
Top achievements
Rank 2
Joel
Top achievements
Rank 1
Bob
Top achievements
Rank 1
Uncle Steve
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or